source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | spec/lib/auth0/api/v2/connections_spec.rb | Ruby | mit | 204 | master | 5,667 | require 'spec_helper'
describe Auth0::Api::V2::Connections do
before :all do
dummy_instance = DummyClass.new
dummy_instance.extend(Auth0::Api::V2::Connections)
@instance = dummy_instance
end
context '.connections' do
it { expect(@instance).to respond_to(:connections) }
it { expect(@instance).... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | spec/lib/auth0/api/v2/tenants_spec.rb | Ruby | mit | 204 | master | 1,130 | require 'spec_helper'
describe Auth0::Api::V2::Tenants do
before :all do
@instance = DummyClass.new.extend(Auth0::Api::V2::Tenants)
end
context '.get_tenant_settings' do
it { expect(@instance).to respond_to(:get_tenant_settings) }
it 'expect client to send post to /api/v2/tenants/settings with fields... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | spec/lib/auth0/api/v2/client_grants_spec.rb | Ruby | mit | 204 | master | 4,003 | require 'spec_helper'
describe Auth0::Api::V2::ClientGrants do
before :all do
dummy_instance = DummyClass.new
dummy_instance.extend(Auth0::Api::V2::ClientGrants)
@instance = dummy_instance
end
context '.client_grants' do
it { expect(@instance).to respond_to(:client_grants) }
it { expect(@inst... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | spec/lib/auth0/api/v2/prompts_spec.rb | Ruby | mit | 204 | master | 3,108 | require 'spec_helper'
describe Auth0::Api::V2::Prompts do
before :all do
dummy_instance = DummyClass.new
dummy_instance.extend(Auth0::Api::V2::Prompts)
@instance = dummy_instance
end
context '.prompts' do
it 'is expected to respond to a prompts method' do
expect(@instance).to respond_to(:pr... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | spec/lib/auth0/api/v2/attack_protection_spec.rb | Ruby | mit | 204 | master | 4,111 | require 'spec_helper'
describe Auth0::Api::V2::AttackProtection do
before :all do
dummy_instance = DummyClass.new
dummy_instance.extend(Auth0::Api::V2::AttackProtection)
@instance = dummy_instance
end
context '.get breached-password-detection' do
it 'responds to a breached_password_detection met... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | spec/lib/auth0/api/v2/users_by_email_spec.rb | Ruby | mit | 204 | master | 609 | require 'spec_helper'
describe Auth0::Api::V2::UsersByEmail do
before :all do
dummy_instance = DummyClass.new
dummy_instance.extend(Auth0::Api::V2::UsersByEmail)
@instance = dummy_instance
end
context '.users_by_email' do
it { expect(@instance).to respond_to(:users_by_email) }
it 'is expected... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | spec/lib/auth0/api/v2/jobs_spec.rb | Ruby | mit | 204 | master | 5,420 | require 'spec_helper'
describe Auth0::Api::V2::Jobs do
before :all do
dummy_instance = DummyClass.new
dummy_instance.extend(Auth0::Api::V2::Jobs)
@instance = dummy_instance
end
context '.get_job' do
it { expect(@instance).to respond_to(:get_job) }
it 'expect client to send get to /api/v2/stats... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | spec/lib/auth0/api/v2/device_credentials_spec.rb | Ruby | mit | 204 | master | 4,057 | require 'spec_helper'
describe Auth0::Api::V2::DeviceCredentials do
before :all do
dummy_instance = DummyClass.new
dummy_instance.extend(Auth0::Api::V2::DeviceCredentials)
@instance = dummy_instance
end
context '.device_credentials' do
it { expect(@instance).to respond_to(:device_credentials) }
... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | spec/support/dummy_class.rb | Ruby | mit | 204 | master | 441 | class DummyClass
include Auth0::Mixins::Headers
attr_reader :domain, :client_id, :client_secret, :audience
def initialize
@domain = 'test.auth0.com'
@client_id = '__test_client_id__'
@client_secret = '__test_client_secret__'
@audience = "https://#{@domain}/api/v2/"
end
%i(get post put patch... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | spec/support/dummy_class_for_tokens.rb | Ruby | mit | 204 | master | 698 | class DummyClassForTokens
include Auth0::Mixins::HTTPProxy
include Auth0::Mixins::Headers
include Auth0::Mixins::TokenManagement
include Auth0::Mixins::Initializer
def initialize(config)
extend Auth0::Api::AuthenticationEndpoints
@client_id = config[:client_id]
@client_secret = config[:client_sec... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | spec/support/credentials.rb | Ruby | mit | 204 | master | 308 | module Credentials
module_function
def v2_creds
{
domain: ENV.fetch( 'DOMAIN', 'DOMAIN' ),
client_id: ENV.fetch( 'CLIENT_ID', 'CLIENT_ID' ),
client_secret: ENV.fetch( 'CLIENT_SECRET', 'TEST_CLIENT_SECRET' ),
token: ENV.fetch( 'MASTER_JWT', 'TEST_MASTER_JWT' )
}
end
end |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | spec/integration/lib/auth0/auth0_client_spec.rb | Ruby | mit | 204 | master | 2,870 | require 'spec_helper'
describe Auth0::Client do
shared_examples 'invalid credentials' do |credentials, error|
it "raise an error with credentials #{credentials}" do
if error.nil?
expect { Auth0Client.new(credentials) }.to raise_error
else
expect { Auth0Client.new(credentials) }.to rais... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | spec/integration/lib/auth0/api/api_authentication_spec.rb | Ruby | mit | 204 | master | 3,329 | require 'spec_helper'
describe Auth0::Api::AuthenticationEndpoints do
attr_reader :client, :test_user_email, :test_user_pwd, :test_user
before(:all) do
@client = Auth0Client.new(v2_creds)
@test_user_email = "#{entity_suffix}-username-1@auth0.com"
@test_user_pwd = '23kejn2jk3en2jke2jk3be2jk3ber'
V... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | spec/integration/lib/auth0/api/v2/api_resource_servers_spec.rb | Ruby | mit | 204 | master | 3,531 | require 'spec_helper'
describe Auth0::Api::V2::ResourceServers do
attr_reader :client, :test_server
before(:all) do
@client = Auth0Client.new(v2_creds)
VCR.use_cassette('Auth0_Api_V2_ResourceServers/create_test_server') do
@test_server = client.create_resource_server(
'https://localhost.test... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | spec/integration/lib/auth0/api/v2/api_roles_spec.rb | Ruby | mit | 204 | master | 4,409 | require 'spec_helper'
describe Auth0::Api::V2::Roles do
attr_reader :client, :test_user, :test_role_name, :test_permission, :test_api, :test_role
before(:all) do
@client ||= Auth0::Client.new(v2_creds)
@test_user_name = "#{entity_suffix}-username-for-roles"
@test_user_email = "#{entity_suffix}-#{@tes... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | spec/integration/lib/auth0/api/v2/api_email_spec.rb | Ruby | mit | 204 | master | 2,135 | require 'spec_helper'
describe Auth0::Api::V2::Emails do
attr_reader :client
before(:all) do
@client = Auth0Client.new(v2_creds)
begin
VCR.use_cassette(
'Auth0_Api_V2_Emails/delete_existing_provider'
) do
client.delete_provider
end
rescue Auth0::NotFound
puts 'n... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | spec/integration/lib/auth0/api/v2/api_rules_spec.rb | Ruby | mit | 204 | master | 4,791 | require 'spec_helper'
describe Auth0::Api::V2::Rules do
attr_reader :client, :test_script, :enabled_rule, :disabled_rule
before(:all) do
@client = Auth0Client.new(v2_creds)
@test_script = 'function (user, context, cb) { cb(null, user, context);}'
VCR.use_cassette('Auth0_Api_V2_Rules/create_test_enable... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | spec/integration/lib/auth0/api/v2/api_client_grants_spec.rb | Ruby | mit | 204 | master | 1,804 | require 'spec_helper'
describe Auth0::Api::V2::ClientGrants do
attr_reader :client, :test_client_grant, :test_client
before(:all) do
@client = Auth0Client.new(v2_creds)
VCR.use_cassette('Auth0_Api_V2_ClientGrants/create_test_client') do
@test_client = client.create_client(
"ClientGrantTestCl... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | spec/integration/lib/auth0/api/v2/api_connections_spec.rb | Ruby | mit | 204 | master | 4,216 | require 'spec_helper'
describe Auth0::Api::V2::Connections do
attr_reader :client,
:test_user_name, :test_user_email,
:test_con_name, :test_con_strategy, :test_conn
before(:all) do
@client ||= Auth0Client.new(v2_creds)
@test_user_name = "#{entity_suffix}-username"
@test_user... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | spec/integration/lib/auth0/api/v2/api_tenants_spec.rb | Ruby | mit | 204 | master | 1,515 | require 'spec_helper'
describe Auth0::Api::V2::Tenants do
attr_reader :client
before(:all) do
@client = Auth0Client.new(v2_creds)
end
let(:default_tenant_name) { 'Auth0' }
describe '.get_tenant_settings', vcr: true do
it 'should get the tenant settings' do
expect(
client.get_tenant_se... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | spec/integration/lib/auth0/api/v2/api_stats_spec.rb | Ruby | mit | 204 | master | 586 | require 'spec_helper'
describe Auth0::Api::V2::Stats do
let(:client) { Auth0Client.new(v2_creds) }
describe '.active_users', vcr: true do
it 'should have at least one active user' do
expect(Integer(client.active_users)).to be >= 0
end
end
# rubocop:disable Date
describe '.daily_stats', vcr: tr... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | spec/integration/lib/auth0/api/v2/api_users_spec.rb | Ruby | mit | 204 | master | 8,104 | require 'spec_helper'
describe Auth0::Api::V2::Users do
attr_reader :client, :test_user_name, :test_user_email, :test_user, :test_user_secondary,
:test_role, :test_api_name, :test_permission_name, :test_permission
before(:all) do
@client ||= Auth0::Client.new(v2_creds)
@test_user_name = "#{... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | spec/integration/lib/auth0/api/v2/api_user_blocks_spec.rb | Ruby | mit | 204 | master | 2,088 | require 'spec_helper'
describe Auth0::Api::V2::UserBlocks do
attr_reader :client, :user, :email
skip 'User blocks examples are skipped since is #logins exceeds free tenant limits' do
before(:all) do
@client = Auth0Client.new(v2_creds)
username = Faker::Internet.user_name
@email = "#{entity_su... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | spec/integration/lib/auth0/api/v2/api_jobs_spec.rb | Ruby | mit | 204 | master | 3,891 | require 'spec_helper'
describe Auth0::Api::V2::Jobs do
UP_AUTH = Auth0::Api::AuthenticationEndpoints::UP_AUTH
let(:client) { Auth0Client.new(v2_creds) }
let(:username) { Faker::Internet.user_name }
let(:email) { "#{entity_suffix}#{Faker::Internet.safe_email(name: username)}" }
let(:connection_id) do
VCR.... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | spec/integration/lib/auth0/api/v2/api_tickets_spec.rb | Ruby | mit | 204 | master | 1,808 | require 'spec_helper'
describe Auth0::Api::V2::Tickets do
attr_reader :client, :test_user
before(:all) do
@client = Auth0Client.new(v2_creds)
test_user_name = "#{entity_suffix}-username"
VCR.use_cassette('Auth0_Api_V2_Tickets/create_test_user') do
@test_user = client.create_user(
Auth0::... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | spec/integration/lib/auth0/api/v2/api_logs_spec.rb | Ruby | mit | 204 | master | 2,139 | require 'spec_helper'
describe Auth0::Api::V2::Logs do
attr_reader :client, :test_user
before(:all) do
@client = Auth0Client.new(v2_creds)
test_user_name = "#{entity_suffix}-username"
VCR.use_cassette('Auth0_Api_V2_Logs/create_test_user') do
@test_user = client.create_user(
Auth0::Api::... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | spec/integration/lib/auth0/api/v2/api_clients_spec.rb | Ruby | mit | 204 | master | 4,436 | require 'spec_helper'
describe Auth0::Api::V2::Clients do
attr_reader :client, :test_client_name, :test_client
before(:all) do
@client ||= Auth0Client.new(v2_creds)
@test_client_name = "TestClient-#{entity_suffix}"
VCR.use_cassette('Auth0_Api_V2_Clients/create_test_client') do
@test_client ||= ... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | spec/integration/lib/auth0/api/v2/api_blacklist_spec.rb | Ruby | mit | 204 | master | 667 | require 'spec_helper'
describe Auth0::Api::V2::Blacklists do
let(:client) { Auth0Client.new(v2_creds) }
let(:token) { 'faketoken' }
describe '.add_token_to_blacklist', vcr: true do
it 'should add a token to the blacklist' do
expect do
client.add_token_to_blacklist(
token,
v2... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | examples/ruby-on-rails-api/Gemfile | Ruby | mit | 204 | master | 1,527 | source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '5.0.0.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3', groups: [:development, :test]
gem 'pg'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0.6'
# Use Uglifier as compressor for JavaScript... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | examples/ruby-on-rails-api/db/schema.rb | Ruby | mit | 204 | master | 788 | # encoding: UTF-8
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# Note that this schema.rb definition is the authoritative sou... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | examples/ruby-on-rails-api/config/application.rb | Ruby | mit | 204 | master | 988 | require File.expand_path('../boot', __FILE__)
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module Auth0RorapiSample
class Application < Rails::Application
# Settings in config/environments/* ... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | examples/ruby-on-rails-api/config/routes.rb | Ruby | mit | 204 | master | 1,673 | Rails.application.routes.draw do
get 'ping' => 'ping#ping'
get 'secured/ping' => 'secured_ping#ping'
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
# You can have the root of your site routed with "root"
# root 'welco... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | examples/ruby-on-rails-api/config/initializers/knock.rb | Ruby | mit | 204 | master | 865 | require 'base64'
Knock.setup do |config|
## Expiration claim
## ----------------
##
## How long before a token is expired.
##
## Default:
# config.token_lifetime = 1.day
## Audience claim
## --------------
##
## Configure the audience claim to indentify the recipients that the token
## is inte... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | examples/ruby-on-rails-api/config/environments/test.rb | Ruby | mit | 204 | master | 1,705 | Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suit... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | examples/ruby-on-rails-api/config/environments/production.rb | Ruby | mit | 204 | master | 3,349 | Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# Code is not reloaded between requests.
config.cache_classes = true
# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web serve... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | examples/ruby-on-rails-api/app/controllers/secured_ping_controller.rb | Ruby | mit | 204 | master | 264 | # Secured ping Controller
class SecuredPingController < ApplicationController
before_action :authenticate_user
def ping
render json: {
message: "All good. You only get this message if you're authenticated.",
user: current_user
}
end
end |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | examples/ruby-on-rails-api/app/controllers/application_controller.rb | Ruby | mit | 204 | master | 264 | # Application Controller
class ApplicationController < ActionController::Base
include Knock::Authenticable
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :null_session
end |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | examples/ruby-on-rails-api/test/test_helper.rb | Ruby | mit | 204 | master | 505 | ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
# Active Support
class ActiveSupport
# Test Case
class TestCase
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
#
# Note: You'll currently still have to d... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | examples/ruby-on-rails-api/test/secured_ping_controller_test.rb | Ruby | mit | 204 | master | 691 | require 'test_helper'
# Secure Ping Controller Test
class SecuredPingControllerTest < ActionController::TestCase
def with_a_valid_token
@user = { id: 1 }
@token = Knock::AuthToken.new(payload: { sub: @user[:id] }).token
@request.env['HTTP_AUTHORIZATION'] = "Bearer #{@token}"
end
test 'responds with u... |
github | auth0/ruby-auth0 | https://github.com/auth0/ruby-auth0 | examples/ruby-api/main.rb | Ruby | mit | 204 | master | 800 | require 'dotenv'
require 'jwt'
require 'sinatra'
Dotenv.load '.env'
set :show_exceptions, false
class InvalidTokenError < StandardError
end
def validate_token(env)
auth0_client_id = ENV['AUTH0_CLIENT_ID']
auth0_client_secret = ENV['AUTH0_CLIENT_SECRET']
authorization = env['HTTP_AUTHORIZATION']
raise InvalidT... |
github | pushpad/web-push | https://github.com/pushpad/web-push | web-push.gemspec | Ruby | mit | 204 | master | 679 | require_relative 'lib/web_push/version'
Gem::Specification.new do |spec|
spec.name = 'web-push'
spec.version = WebPush::VERSION
spec.license = 'MIT'
spec.authors = ['zaru', 'collimarco']
spec.email = ['support@pushpad.xyz']
spec.summary = 'Web Push library for Ruby (RFC8030)'
spec.homepage = 'https://gi... |
github | pushpad/web-push | https://github.com/pushpad/web-push | lib/web_push.rb | Ruby | mit | 204 | master | 2,244 | # frozen_string_literal: true
require 'openssl'
require 'base64'
require 'jwt'
require 'uri'
require 'net/http'
require 'json'
require 'web_push/version'
require 'web_push/errors'
require 'web_push/vapid_key'
require 'web_push/encryption'
require 'web_push/request'
# Push API implementation
#
# https://tools.ietf.or... |
github | pushpad/web-push | https://github.com/pushpad/web-push | lib/web_push/errors.rb | Ruby | mit | 204 | master | 643 | # frozen_string_literal: true
module WebPush
class Error < RuntimeError; end
class ConfigurationError < Error; end
class ResponseError < Error
attr_reader :response, :host
def initialize(response, host)
@response = response
@host = host
super "host: #{host}, #{@response.inspect}\nbod... |
github | pushpad/web-push | https://github.com/pushpad/web-push | lib/web_push/encryption.rb | Ruby | mit | 204 | master | 2,417 | # frozen_string_literal: true
module WebPush
module Encryption
extend self
def encrypt(message, p256dh, auth)
assert_arguments(message, p256dh, auth)
group_name = 'prime256v1'
hash = 'SHA256'
salt = Random.new.bytes(16)
server = OpenSSL::PKey::EC.generate(group_name)
se... |
github | pushpad/web-push | https://github.com/pushpad/web-push | lib/web_push/vapid_key.rb | Ruby | mit | 204 | master | 3,384 | # frozen_string_literal: true
module WebPush
# Class for abstracting the generation and encoding of elliptic curve public and private keys for use with the VAPID protocol
#
# @attr_reader [OpenSSL::PKey::EC] :curve the OpenSSL elliptic curve instance
class VapidKey
# Create a VapidKey instance from encoded... |
github | pushpad/web-push | https://github.com/pushpad/web-push | lib/web_push/request.rb | Ruby | mit | 204 | master | 4,171 | # frozen_string_literal: true
module WebPush
class Request
def initialize(message: '', subscription:, vapid:, **options)
endpoint = subscription.fetch(:endpoint)
@endpoint = endpoint
@payload = build_payload(message, subscription)
@vapid_options = vapid
@options = default_options.m... |
github | pushpad/web-push | https://github.com/pushpad/web-push | spec/web_push_spec.rb | Ruby | mit | 204 | master | 8,881 | require 'spec_helper'
describe WebPush do
it 'has a version number' do
expect(WebPush::VERSION).not_to be nil
end
describe '.decode64' do
let(:a_padded_key) { "YWJjZGU=" }
it 'urlsafe decodes padded base64 string' do
expect(WebPush.decode64(a_padded_key)).to eq("abcde")
end
it 'urlsa... |
github | pushpad/web-push | https://github.com/pushpad/web-push | spec/spec_helper.rb | Ruby | mit | 204 | master | 499 | require 'simplecov'
SimpleCov.start do
add_filter '/spec/'
end
require 'web_push'
require 'webmock/rspec'
WebMock.disable_net_connect!(allow_localhost: true)
def vapid_options
{
subject: 'mailto:sender@example.com',
public_key: vapid_public_key,
private_key: vapid_private_key
}
end
def vapid_publi... |
github | pushpad/web-push | https://github.com/pushpad/web-push | spec/web_push/encryption_spec.rb | Ruby | mit | 204 | master | 3,681 | require 'spec_helper'
describe WebPush::Encryption do
describe '#encrypt' do
let(:curve) do
group = 'prime256v1'
OpenSSL::PKey::EC.generate(group)
end
let(:p256dh) do
ecdh_key = curve.public_key.to_bn.to_s(2)
Base64.urlsafe_encode64(ecdh_key)
end
let(:auth) { Base64.urls... |
github | pushpad/web-push | https://github.com/pushpad/web-push | spec/web_push/request_spec.rb | Ruby | mit | 204 | master | 3,588 | require 'spec_helper'
describe WebPush::Request do
describe '#headers' do
let(:request) { build_request }
it { expect(request.headers['Content-Type']).to eq('application/octet-stream') }
it { expect(request.headers['Ttl']).to eq('2419200') }
it { expect(request.headers['Urgency']).to eq('normal') }
... |
github | pushpad/web-push | https://github.com/pushpad/web-push | spec/web_push/vapid_key_spec.rb | Ruby | mit | 204 | master | 3,002 | require 'spec_helper'
describe WebPush::VapidKey do
it 'generates an elliptic curve' do
key = WebPush::VapidKey.new
expect(key.curve).to be_a(OpenSSL::PKey::EC)
expect(key.curve_name).to eq('prime256v1')
end
it 'returns an encoded public key' do
key = WebPush::VapidKey.new
expect(Base64.url... |
github | DmitryTsepelev/io_monitor | https://github.com/DmitryTsepelev/io_monitor | Gemfile | Ruby | mit | 204 | main | 359 | source "https://rubygems.org"
gem "rake", "~> 13.0"
gem "rspec", "~> 3.0"
gem "rspec-rails", "~> 5.0"
gem "with_model", "~> 2.0"
gem "database_cleaner-active_record", "~> 2.0"
gem "standard", "~> 1.18.0"
gem "simplecov", "~> 0.21.0"
gem "pry"
gem "webmock", "~> 3.14"
gem "concurrent-ruby", "1.3.4"
gem "sqlite3", "~> 1... |
github | DmitryTsepelev/io_monitor | https://github.com/DmitryTsepelev/io_monitor | io_monitor.gemspec | Ruby | mit | 204 | main | 1,229 | # frozen_string_literal: true
require_relative "lib/io_monitor/version"
Gem::Specification.new do |spec|
spec.name = "io_monitor"
spec.version = IoMonitor::VERSION
spec.authors = ["baygeldin", "prog-supdex", "maxshend", "DmitryTsepelev"]
spec.email = ["dmitry.a.tsepelev@gmail.com"]
spec.homepage = "https://... |
github | DmitryTsepelev/io_monitor | https://github.com/DmitryTsepelev/io_monitor | lib/io_monitor.rb | Ruby | mit | 204 | main | 1,104 | # frozen_string_literal: true
require "io_monitor/version"
require "io_monitor/configuration"
require "io_monitor/aggregator"
require "io_monitor/controller"
require "io_monitor/adapters/base_adapter"
require "io_monitor/adapters/active_record_adapter"
require "io_monitor/adapters/net_http_adapter"
require "io_monit... |
github | DmitryTsepelev/io_monitor | https://github.com/DmitryTsepelev/io_monitor | lib/io_monitor/railtie.rb | Ruby | mit | 204 | main | 658 | # frozen_string_literal: true
require "io_monitor/patches/action_controller_base_patch"
module IoMonitor
class Railtie < Rails::Railtie
config.after_initialize do
IoMonitor.config.adapters.each(&:initialize!)
ActiveSupport.on_load(:action_controller) do
ActionController::Base.singleton_clas... |
github | DmitryTsepelev/io_monitor | https://github.com/DmitryTsepelev/io_monitor | lib/io_monitor/configuration.rb | Ruby | mit | 204 | main | 1,493 | # frozen_string_literal: true
module IoMonitor
class Configuration
DEFAULT_WARN_THRESHOLD = 0.0
def initialize
@publishers = [LogsPublisher.new]
@adapters = [ActiveRecordAdapter.new]
@warn_threshold = DEFAULT_WARN_THRESHOLD
end
attr_reader :publishers, :adapters, :warn_threshold
... |
github | DmitryTsepelev/io_monitor | https://github.com/DmitryTsepelev/io_monitor | lib/io_monitor/aggregator.rb | Ruby | mit | 204 | main | 893 | # frozen_string_literal: true
module IoMonitor
# Thread-safe payload size aggregator.
class Aggregator
def initialize(sources)
@sources = sources
end
attr_reader :sources
def active?
InputPayload.active.present?
end
def collect
start!
yield
stop!
end
... |
github | DmitryTsepelev/io_monitor | https://github.com/DmitryTsepelev/io_monitor | lib/io_monitor/controller.rb | Ruby | mit | 204 | main | 1,065 | # frozen_string_literal: true
module IoMonitor
module Controller
extend ActiveSupport::Concern
delegate :aggregator, to: IoMonitor
ALL_ACTIONS = Object.new
class_methods do
def monitor_io_for(*actions_to_monitor_io)
@actions_to_monitor_io = actions_to_monitor_io
end
def ... |
github | DmitryTsepelev/io_monitor | https://github.com/DmitryTsepelev/io_monitor | lib/io_monitor/adapters/redis_adapter.rb | Ruby | mit | 204 | main | 297 | # frozen_string_literal: true
require "io_monitor/patches/redis_patch"
module IoMonitor
class RedisAdapter < BaseAdapter
def self.kind
:redis
end
def initialize!
ActiveSupport.on_load(:after_initialize) do
Redis.prepend(RedisPatch)
end
end
end
end |
github | DmitryTsepelev/io_monitor | https://github.com/DmitryTsepelev/io_monitor | lib/io_monitor/adapters/net_http_adapter.rb | Ruby | mit | 204 | main | 535 | # frozen_string_literal: true
require "net/http"
require "io_monitor/patches/net_http_adapter_patch"
module IoMonitor
class NetHttpAdapter < BaseAdapter
def self.kind
:net_http
end
def initialize!
ActiveSupport.on_load(:after_initialize) do
Net::HTTP.prepend(NetHttpAdapterPatch)
... |
github | DmitryTsepelev/io_monitor | https://github.com/DmitryTsepelev/io_monitor | lib/io_monitor/adapters/base_adapter.rb | Ruby | mit | 204 | main | 225 | # frozen_string_literal: true
module IoMonitor
class BaseAdapter
# :nocov:
def self.kind
raise NotImplementedError
end
def initialize!
raise NotImplementedError
end
# :nocov:
end
end |
github | DmitryTsepelev/io_monitor | https://github.com/DmitryTsepelev/io_monitor | lib/io_monitor/adapters/active_record_adapter.rb | Ruby | mit | 204 | main | 998 | # frozen_string_literal: true
require "io_monitor/patches/abstract_adapter_patch"
require "io_monitor/patches/future_result_patch"
module IoMonitor
class ActiveRecordAdapter < BaseAdapter
class << self
def kind
:active_record
end
def aggregate_result(rows:)
return unless IoMon... |
github | DmitryTsepelev/io_monitor | https://github.com/DmitryTsepelev/io_monitor | lib/io_monitor/patches/net_http_adapter_patch.rb | Ruby | mit | 204 | main | 322 | # frozen_string_literal: true
module IoMonitor
module NetHttpAdapterPatch
def request(*args, &block)
super.tap do |response|
if response&.body && IoMonitor.aggregator.active?
IoMonitor.aggregator.increment(NetHttpAdapter.kind, response.body.bytesize)
end
end
end
end
en... |
github | DmitryTsepelev/io_monitor | https://github.com/DmitryTsepelev/io_monitor | lib/io_monitor/patches/future_result_patch.rb | Ruby | mit | 204 | main | 327 | # frozen_string_literal: true
module IoMonitor
module FutureResultPatch
def result
# @event_buffer is used to send ActiveSupport notifications related to async queries
return super unless @event_buffer
res = super
ActiveRecordAdapter.aggregate_result rows: res.rows
res
end
e... |
github | DmitryTsepelev/io_monitor | https://github.com/DmitryTsepelev/io_monitor | lib/io_monitor/patches/redis_patch.rb | Ruby | mit | 204 | main | 514 | # frozen_string_literal: true
module IoMonitor
module RedisPatch
def send_command(command, &block)
super(command, &block).tap do |reply|
# we need to check QUEUED because of https://github.com/redis/redis-rb/blob/cbdb53e8c2f0be53c91404cb7ff566a36fc8ebf5/lib/redis/client.rb#L164
if reply != ... |
github | DmitryTsepelev/io_monitor | https://github.com/DmitryTsepelev/io_monitor | lib/io_monitor/patches/abstract_adapter_patch.rb | Ruby | mit | 204 | main | 218 | # frozen_string_literal: true
module IoMonitor
module AbstractAdapterPatch
def build_result(*args, **kwargs, &block)
ActiveRecordAdapter.aggregate_result rows: kwargs[:rows]
super
end
end
end |
github | DmitryTsepelev/io_monitor | https://github.com/DmitryTsepelev/io_monitor | lib/io_monitor/patches/action_controller_base_patch.rb | Ruby | mit | 204 | main | 536 | # frozen_string_literal: true
module IoMonitor
module ActionControllerBasePatch
def log_process_action(payload)
super.tap do |messages|
next unless IoMonitor.config.publishers.any? { |publisher| publisher.is_a?(LogsPublisher) }
data = payload[IoMonitor::NAMESPACE]
next unless data
... |
github | DmitryTsepelev/io_monitor | https://github.com/DmitryTsepelev/io_monitor | lib/io_monitor/publishers/logs_publisher.rb | Ruby | mit | 204 | main | 367 | # frozen_string_literal: true
module IoMonitor
class LogsPublisher < BasePublisher
def self.kind
:logs
end
def publish(source, ratio)
Rails.logger.warn <<~HEREDOC.squish
#{source.to_s.camelize} I/O to response payload ratio is #{ratio},
while threshold is #{IoMonitor.config.w... |
github | DmitryTsepelev/io_monitor | https://github.com/DmitryTsepelev/io_monitor | lib/io_monitor/publishers/prometheus_publisher.rb | Ruby | mit | 204 | main | 1,281 | # frozen_string_literal: true
module IoMonitor
class PrometheusPublisher < BasePublisher
HELP_MESSAGE = "IO payload size to response payload size ratio"
def initialize(registry: nil, aggregation: nil, buckets: nil)
registry ||= ::Prometheus::Client.registry
@metric = registry.histogram(
... |
github | DmitryTsepelev/io_monitor | https://github.com/DmitryTsepelev/io_monitor | lib/io_monitor/publishers/notifications_publisher.rb | Ruby | mit | 204 | main | 512 | # frozen_string_literal: true
module IoMonitor
class NotificationsPublisher < BasePublisher
WARN_THRESHOLD_REACHED_EVENT = "warn_threshold_reached"
def self.kind
:notifications
end
def publish(source, ratio)
ActiveSupport::Notifications.instrument(
full_event_name(WARN_THRESHOLD... |
github | DmitryTsepelev/io_monitor | https://github.com/DmitryTsepelev/io_monitor | lib/io_monitor/publishers/base_publisher.rb | Ruby | mit | 204 | main | 613 | # frozen_string_literal: true
module IoMonitor
class BasePublisher
# :nocov:
def self.kind
raise NotImplementedError
end
def publish(source, ratio)
raise NotImplementedError
end
# :nocov:
def process_action(payload)
(payload.keys - [:response]).each do |source|
... |
github | DmitryTsepelev/io_monitor | https://github.com/DmitryTsepelev/io_monitor | spec/io_monitor_spec.rb | Ruby | mit | 204 | main | 1,009 | # frozen_string_literal: true
RSpec.describe IoMonitor do
subject { described_class }
it "has a version number" do
expect(subject::VERSION).not_to be nil
end
describe ".configure" do
it "yields config" do
expect(subject).to receive(:configure).and_yield(subject.config)
subject.configure ... |
github | DmitryTsepelev/io_monitor | https://github.com/DmitryTsepelev/io_monitor | spec/spec_helper.rb | Ruby | mit | 204 | main | 1,022 | # frozen_string_literal: true
require "webmock/rspec"
require "simplecov"
SimpleCov.start if ENV["COVERAGE"]
ENV["RAILS_ENV"] = "test"
require "redis"
require_relative "dummy/config/environment"
require "rspec/rails"
require "io_monitor"
RSpec.configure do |config|
# For proper work of ActiveSupport::CurrentAtt... |
github | DmitryTsepelev/io_monitor | https://github.com/DmitryTsepelev/io_monitor | spec/io_monitor/configuration_spec.rb | Ruby | mit | 204 | main | 2,259 | # frozen_string_literal: true
RSpec.describe IoMonitor::Configuration do
subject(:config) { described_class.new }
describe ".publish" do
it "resolves publisher by kind" do
config.publish = :notifications
expect(config.publishers.first).to be_a(IoMonitor::NotificationsPublisher)
end
contex... |
github | DmitryTsepelev/io_monitor | https://github.com/DmitryTsepelev/io_monitor | spec/io_monitor/aggregator_spec.rb | Ruby | mit | 204 | main | 1,625 | # frozen_string_literal: true
RSpec.describe IoMonitor::Aggregator do
subject(:aggregator) { described_class.new(sources) }
let(:sources) { %i[active_record] }
describe ".active?" do
it "false by default" do
expect(aggregator.active?).to be false
end
end
describe ".start!" do
it "makes i... |
github | DmitryTsepelev/io_monitor | https://github.com/DmitryTsepelev/io_monitor | spec/io_monitor/controller_spec.rb | Ruby | mit | 204 | main | 3,650 | # frozen_string_literal: true
RSpec.describe IoMonitor::Controller, type: :controller do
controller(ApplicationController) do
include IoMonitor::Controller
def index
render json: Fake.all
end
end
with_model :Fake, scope: :all do
table do |t|
t.string :name
end
model {}
en... |
github | DmitryTsepelev/io_monitor | https://github.com/DmitryTsepelev/io_monitor | spec/io_monitor/publishers/logs_publisher_spec.rb | Ruby | mit | 204 | main | 424 | # frozen_string_literal: true
require_relative "shared_examples"
RSpec.describe IoMonitor::LogsPublisher do
subject(:publisher) { described_class.new }
it_behaves_like "publisher"
describe ".publish" do
it "logs a warning" do
msg = /ActiveRecord I\/O to response payload ratio is 0.5/
expect(Ra... |
github | DmitryTsepelev/io_monitor | https://github.com/DmitryTsepelev/io_monitor | spec/io_monitor/publishers/prometheus_publisher_spec.rb | Ruby | mit | 204 | main | 671 | # frozen_string_literal: true
require_relative "shared_examples"
require "prometheus/client"
RSpec.describe IoMonitor::PrometheusPublisher do
subject(:publisher) { described_class.new(registry: registry) }
let(:registry) { ::Prometheus::Client.registry }
let(:metric) { ::Prometheus::Client::Histogram.new(:test... |
github | DmitryTsepelev/io_monitor | https://github.com/DmitryTsepelev/io_monitor | spec/io_monitor/publishers/shared_examples.rb | Ruby | mit | 204 | main | 1,827 | # frozen_string_literal: true
RSpec.shared_examples "publisher" do |parameter|
describe ".process_action" do
let(:event) { "process_action.action_controller" }
let(:full_payload) { {IoMonitor::NAMESPACE => payload} }
let(:payload) do
{
io_kind => io_payload_size,
:response => respo... |
github | DmitryTsepelev/io_monitor | https://github.com/DmitryTsepelev/io_monitor | spec/io_monitor/publishers/notifications_publisher_spec.rb | Ruby | mit | 204 | main | 536 | # frozen_string_literal: true
require_relative "shared_examples"
RSpec.describe IoMonitor::NotificationsPublisher do
subject(:publisher) { described_class.new }
it_behaves_like "publisher"
describe ".publish" do
it "instruments warn_threshold_reached event" do
warn_event = "warn_threshold_reached.#{... |
github | DmitryTsepelev/io_monitor | https://github.com/DmitryTsepelev/io_monitor | spec/io_monitor/adapters/net_http_adapter_spec.rb | Ruby | mit | 204 | main | 771 | # frozen_string_literal: true
RSpec.describe IoMonitor::NetHttpAdapter do
let(:aggregator) { IoMonitor.aggregator }
let(:body) { "Hello, World!" }
let(:url) { "www.example.com" }
before do
stub_request(:get, url).to_return body: body
end
around do |example|
aggregator.collect { example.run }
en... |
github | DmitryTsepelev/io_monitor | https://github.com/DmitryTsepelev/io_monitor | spec/io_monitor/adapters/redis_adapter_spec.rb | Ruby | mit | 204 | main | 1,480 | # frozen_string_literal: true
require_relative "../../../lib/io_monitor/adapters/redis_adapter"
RSpec.describe IoMonitor::RedisAdapter do
let(:aggregator) { IoMonitor.aggregator }
let(:key) { "key" }
let(:value) { "Hello, World!" }
let(:redis_client) { instance_double(Redis::Client) }
let(:redis) { Redis.... |
github | DmitryTsepelev/io_monitor | https://github.com/DmitryTsepelev/io_monitor | spec/io_monitor/adapters/active_record_adapter_spec.rb | Ruby | mit | 204 | main | 1,410 | # frozen_string_literal: true
RSpec.describe IoMonitor::ActiveRecordAdapter do
let(:aggregator) { IoMonitor.aggregator }
with_model :Fake, scope: :all do
table do |t|
t.string :name
end
model {}
end
before(:all) do
(1..10).each { |i| Fake.create!(name: "Fake #{i}") }
end
after(:al... |
github | DmitryTsepelev/io_monitor | https://github.com/DmitryTsepelev/io_monitor | spec/dummy/config/application.rb | Ruby | mit | 204 | main | 653 | # frozen_string_literal: true
require_relative "boot"
require "rails"
require "active_model/railtie"
require "active_record/railtie"
require "action_controller/railtie"
require "rails/test_unit/railtie"
Bundler.require(*Rails.groups)
module Dummy
class Application < Rails::Application
config.root = File.join(... |
github | thekompanee/chamber | https://github.com/thekompanee/chamber | chamber.gemspec | Ruby | mit | 204 | master | 2,287 | # encoding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'chamber/version'
Gem::Specification.new do |spec|
spec.name = 'chamber'
spec.version = Chamber::VERSION
spec.authors = ['thekompanee', 'jfelchner', 'stevenhallen', 'm... |
github | thekompanee/chamber | https://github.com/thekompanee/chamber | lib/chamber.rb | Ruby | mit | 204 | master | 1,586 | # frozen_string_literal: true
require 'chamber/rubinius_fix'
require 'chamber/instance'
require 'chamber/rails'
module Chamber
attr_writer :instance
def load(**args)
self.instance = Instance.new(**args)
end
def instance
@instance ||= Instance.new
end
def [](key)
instance.[](key)
end
d... |
github | thekompanee/chamber | https://github.com/thekompanee/chamber | lib/chamber/file_set.rb | Ruby | mit | 204 | master | 8,223 | # frozen_string_literal: true
require 'pathname'
require 'chamber/namespace_set'
require 'chamber/file'
require 'chamber/settings'
###
# Internal: Represents a set of settings files that should be considered for
# processing. Whether they actually *are* processed depends on their extension
# (only *.yml and *.yml.er... |
github | thekompanee/chamber | https://github.com/thekompanee/chamber | lib/chamber/context_resolver.rb | Ruby | mit | 204 | master | 3,598 | # frozen_string_literal: true
require 'pathname'
require 'socket'
require 'chamber/keys/decryption'
require 'chamber/keys/encryption'
module Chamber
class ContextResolver
attr_accessor :options
def self.resolve(**args)
new(**args).resolve
end
def initialize(**args)
self.options = args
end
#... |
github | thekompanee/chamber | https://github.com/thekompanee/chamber | lib/chamber/settings.rb | Ruby | mit | 204 | master | 10,448 | # frozen_string_literal: true
require 'chamber/errors/missing_index'
require 'chamber/errors/missing_setting'
require 'chamber/namespace_set'
require 'chamber/filters/namespace_filter'
require 'chamber/filters/encryption_filter'
require 'chamber/filters/decryption_filter'
require 'chamber/filters/environment_filter'
r... |
github | thekompanee/chamber | https://github.com/thekompanee/chamber | lib/chamber/file.rb | Ruby | mit | 204 | master | 6,180 | # frozen_string_literal: true
require 'pathname'
require 'yaml'
require 'erb'
require 'chamber/files/signature'
###
# Internal: Represents a single file containing settings information in a given
# file set.
#
module Chamber
class File < Pathname
attr_accessor :namespaces,
:decryption_keys,
... |
github | thekompanee/chamber | https://github.com/thekompanee/chamber | lib/chamber/rubinius_fix.rb | Ruby | mit | 204 | master | 212 | # frozen_string_literal: true
require 'pathname'
unless Pathname.method_defined?(:write)
class Pathname
def write(*args)
IO.write @path, *args # rubocop:disable Security/IoMethods
end
end
end |
github | thekompanee/chamber | https://github.com/thekompanee/chamber | lib/chamber/key_pair.rb | Ruby | mit | 204 | master | 1,885 | # frozen_string_literal: true
require 'pathname'
require 'securerandom'
module Chamber
class KeyPair
attr_accessor :key_file_path,
:namespace,
:passphrase
def initialize(key_file_path:, namespace: nil, passphrase: ::SecureRandom.uuid)
self.namespace = namespace
self.p... |
github | thekompanee/chamber | https://github.com/thekompanee/chamber | lib/chamber/namespace_set.rb | Ruby | mit | 204 | master | 4,546 | # frozen_string_literal: true
###
# Internal: Respresents a set of namespaces which will be processed by Chamber
# at various stages when settings are loaded.
#
# The main function that this class provides is the ability to create
# a NamespaceSet from either an array-like or hash-like object and the ability
# to allo... |
github | thekompanee/chamber | https://github.com/thekompanee/chamber | lib/chamber/configuration.rb | Ruby | mit | 204 | master | 1,045 | # frozen_string_literal: true
require 'chamber/context_resolver'
module Chamber
class Configuration
attr_accessor :basepath,
:decryption_keys,
:encryption_keys,
:files,
:namespaces,
:rootpath,
:signature_name
def i... |
github | thekompanee/chamber | https://github.com/thekompanee/chamber | lib/chamber/instance.rb | Ruby | mit | 204 | master | 1,624 | # frozen_string_literal: true
require 'chamber/configuration'
require 'chamber/file_set'
require 'chamber/settings'
module Chamber
class Instance
attr_accessor :configuration,
:files
def initialize(**args)
self.configuration = Configuration.new(**args)
self.files = FileSet.new(... |
github | thekompanee/chamber | https://github.com/thekompanee/chamber | lib/chamber/commands/base.rb | Ruby | mit | 204 | master | 538 | # frozen_string_literal: true
require 'pathname'
require 'chamber/instance'
module Chamber
module Commands
class Base
attr_accessor :chamber,
:dry_run,
:rootpath,
:shell
def self.call(**args)
new(**args).call
end
def initialize(shell: nil, rootpath: ni... |
github | thekompanee/chamber | https://github.com/thekompanee/chamber | lib/chamber/commands/sign.rb | Ruby | mit | 204 | master | 257 | # frozen_string_literal: true
require 'chamber/commands/base'
module Chamber
module Commands
class Sign < Chamber::Commands::Base
def initialize(**args)
super(**args.merge(namespaces: ['*']))
end
def call
chamber.sign
end
end
end
end |
github | thekompanee/chamber | https://github.com/thekompanee/chamber | lib/chamber/commands/unsecure.rb | Ruby | mit | 204 | master | 671 | # frozen_string_literal: true
require 'chamber/commands/base'
require 'chamber/commands/securable'
module Chamber
module Commands
class Unsecure < Chamber::Commands::Base
include Chamber::Commands::Securable
def initialize(**args)
super(**args.merge(namespaces: ['*']))
end
def call
disable_warni... |
github | thekompanee/chamber | https://github.com/thekompanee/chamber | lib/chamber/commands/comparable.rb | Ruby | mit | 204 | master | 684 | # frozen_string_literal: true
require 'tempfile'
module Chamber
module Commands
module Comparable
def initialize(keys_only:, **args)
super
self.keys_only = keys_only
end
def call
system("git diff --no-index #{first_settings_file} #{second_settings_file}")
end
protected
attr_accessor :ke... |
github | thekompanee/chamber | https://github.com/thekompanee/chamber | lib/chamber/commands/securable.rb | Ruby | mit | 204 | master | 1,627 | # frozen_string_literal: true
require 'shellwords'
require 'chamber/instance'
module Chamber
module Commands
module Securable
def initialize(only_sensitive: nil, **args)
super(**args)
ignored_settings_options = args
.merge(files: ignored_settings_filepaths)... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.