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 | delano/otto | https://github.com/delano/otto | examples/advanced_routes/app/logic/transform_logic.rb | Ruby | mit | 19 | main | 407 | # frozen_string_literal: true
class TransformLogic
attr_reader :context, :params, :locale
def initialize(context, params, locale)
@context = context
@params = params
@locale = locale
end
def process
{
transformation: 'Complete',
input_size: @params.to_s.length,
output_format... |
github | delano/otto | https://github.com/delano/otto | examples/advanced_routes/app/logic/upload_logic.rb | Ruby | mit | 19 | main | 404 | # frozen_string_literal: true
class UploadLogic
attr_reader :context, :params, :locale
def initialize(context, params, locale)
@context = context
@params = params
@locale = locale
end
def process
{
upload: 'Processing complete',
csrf_exempt: true,
files_processed: @params.ke... |
github | delano/otto | https://github.com/delano/otto | examples/advanced_routes/app/logic/data_logic.rb | Ruby | mit | 19 | main | 390 | # frozen_string_literal: true
class DataLogic
attr_reader :context, :params, :locale
def initialize(context, params, locale)
@context = context
@params = params
@locale = locale
end
def process
{
data_logic: 'Processed',
response_format: 'json',
input_data: @params,
}
... |
github | delano/otto | https://github.com/delano/otto | examples/advanced_routes/app/logic/analytics_processor.rb | Ruby | mit | 19 | main | 478 | # frozen_string_literal: true
module Analytics
class Processor
attr_reader :context, :params, :locale
def initialize(context, params, locale)
@context = context
@params = params
@locale = locale
end
def process
{
analytics: 'Processed',
metrics: { users: 123,... |
github | delano/otto | https://github.com/delano/otto | examples/advanced_routes/app/logic/data_processor.rb | Ruby | mit | 19 | main | 495 | # frozen_string_literal: true
class DataProcessor
attr_reader :context, :params, :locale
def initialize(context, params, locale)
@context = context
@params = params
@locale = locale
end
def process
{
processed: 'Data processing complete',
input_params: @params.keys,
timestam... |
github | delano/otto | https://github.com/delano/otto | examples/advanced_routes/app/logic/system/config/manager.rb | Ruby | mit | 19 | main | 507 | # frozen_string_literal: true
module System
module Config
class Manager
attr_reader :context, :params, :locale
def initialize(context, params, locale)
@context = context
@params = params
@locale = locale
end
def process
{
system_config: 'Updated... |
github | delano/otto | https://github.com/delano/otto | examples/advanced_routes/app/logic/v2/logic/processor.rb | Ruby | mit | 19 | main | 489 | # frozen_string_literal: true
module V2
module Logic
class Processor
attr_reader :context, :params, :locale
def initialize(context, params, locale)
@context = context
@params = params
@locale = locale
end
def process
{
v2_processor: 'Complete',
... |
github | delano/otto | https://github.com/delano/otto | examples/advanced_routes/app/logic/v2/logic/dashboard.rb | Ruby | mit | 19 | main | 507 | # frozen_string_literal: true
module V2
module Logic
class Dashboard
attr_reader :context, :params, :locale
def initialize(context, params, locale)
@context = context
@params = params
@locale = locale
end
def process
{
v2_dashboard: 'Rendered',
... |
github | delano/otto | https://github.com/delano/otto | examples/advanced_routes/app/logic/admin/panel.rb | Ruby | mit | 19 | main | 544 | # frozen_string_literal: true
module Admin
class Panel
attr_reader :context, :params, :locale
def initialize(context, params, locale)
@context = context
@params = params
@locale = locale
end
def process
{
admin_panel: 'Logic processed',
namespace: 'Admin',
... |
github | delano/otto | https://github.com/delano/otto | examples/advanced_routes/app/logic/admin/logic/manager.rb | Ruby | mit | 19 | main | 530 | # frozen_string_literal: true
module Admin
module Logic
class Manager
attr_reader :context, :params, :locale
def initialize(context, params, locale)
@context = context
@params = params
@locale = locale
end
def process
{
admin_manager: 'Active',
... |
github | delano/otto | https://github.com/delano/otto | examples/advanced_routes/app/logic/nested/feature/logic.rb | Ruby | mit | 19 | main | 500 | # frozen_string_literal: true
module Nested
module Feature
class Logic
attr_reader :context, :params, :locale
def initialize(context, params, locale)
@context = context
@params = params
@locale = locale
end
def process
{
nested_feature: 'Process... |
github | delano/otto | https://github.com/delano/otto | examples/advanced_routes/app/logic/complex/business/handler.rb | Ruby | mit | 19 | main | 528 | # frozen_string_literal: true
module Complex
module Business
class Handler
attr_reader :context, :params, :locale
def initialize(context, params, locale)
@context = context
@params = params
@locale = locale
end
def process
{
complex_business: 'H... |
github | delano/otto | https://github.com/delano/otto | spec/security_example.rb | Ruby | mit | 19 | main | 5,161 | # spec/security_example.rb
#
# frozen_string_literal: true
# Security Configuration Example for Otto
#
# This example demonstrates how to configure Otto's security features safely.
# By default, Otto applies only basic security headers to avoid breaking
# downstream applications.
require_relative '../lib/otto'
# Basi... |
github | delano/otto | https://github.com/delano/otto | spec/security_validation_spec.rb | Ruby | mit | 19 | main | 25,174 | # spec/security_validation_spec.rb
#
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Otto::Security::ValidationMiddleware do
let(:config) { Otto::Security::Config.new }
let(:app) { ->(_env) { [200, { 'content-type' => 'text/plain' }, ['Hello World']] } }
let(:middleware) { described_class.new... |
github | delano/otto | https://github.com/delano/otto | spec/test_security_defaults.rb | Ruby | mit | 19 | main | 4,837 | # spec/test_security_defaults.rb
#
# frozen_string_literal: true
# Test script to verify Otto's safe security defaults
#
# This script verifies that dangerous security headers are not enabled
# by default and that they can be enabled explicitly when needed.
require_relative '../lib/otto'
def test_safe_defaults
puts... |
github | delano/otto | https://github.com/delano/otto | spec/otto_spec.rb | Ruby | mit | 19 | main | 2,057 | # spec/otto_spec.rb
#
# frozen_string_literal: true
require 'spec_helper'
# This file orchestrates the Otto test suite by including all organized test files.
# Individual test files are organized by functionality in the spec/otto/ directory:
#
# - initialization_spec.rb: Otto instantiation, configuration, and class m... |
github | delano/otto | https://github.com/delano/otto | spec/spec_helper.rb | Ruby | mit | 19 | main | 2,255 | # spec/spec_helper.rb
#
# frozen_string_literal: true
require 'bundler/setup'
require 'rack'
require 'rack/test'
require 'json'
# Load Otto
require_relative '../lib/otto'
# Configure Otto for testing
Otto.debug = ENV['OTTO_DEBUG'] == 'true'
Otto.logger.level = Logger::WARN unless Otto.debug
RSpec.configure do |conf... |
github | delano/otto | https://github.com/delano/otto | spec/security_csrf_spec.rb | Ruby | mit | 19 | main | 19,913 | # spec/security_csrf_spec.rb
#
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Otto::Security::CSRFMiddleware do
let(:config) { Otto::Security::Config.new }
let(:app) { ->(_env) { [200, { 'content-type' => 'text/html' }, ['<html><head></head><body>Hello</body></html>']] } }
let(:middleware) {... |
github | delano/otto | https://github.com/delano/otto | spec/security_config_spec.rb | Ruby | mit | 19 | main | 16,303 | # spec/security_config_spec.rb
#
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Otto::Security::Config do
subject(:config) { described_class.new }
describe 'initialization with safe defaults' do
it 'disables CSRF protection by default' do
expect(config.csrf_protection).to be false
... |
github | delano/otto | https://github.com/delano/otto | spec/support/test_helpers.rb | Ruby | mit | 19 | main | 2,880 | # spec/support/test_helpers.rb
#
# frozen_string_literal: true
require 'rack'
require 'rack/test'
require 'tempfile'
# Test helpers for Otto specs
module OttoTestHelpers
# Unfreeze Otto configuration for testing
# This allows tests to modify configuration after initialization
def unfreeze_otto(otto)
Otto.un... |
github | delano/otto | https://github.com/delano/otto | spec/support/test_applications.rb | Ruby | mit | 19 | main | 2,104 | # spec/support/test_applications.rb
#
# frozen_string_literal: true
# Mock application classes for testing routes
class TestApp
def self.index(_req, res)
res.write('Hello World')
end
def self.show(req, res)
res.write("Showing #{req.params['id']}")
end
def self.user_post(req, res)
res.write("Use... |
github | delano/otto | https://github.com/delano/otto | spec/otto/initialization_spec.rb | Ruby | mit | 19 | main | 12,004 | # spec/otto/initialization_spec.rb
#
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Otto, 'initialization' do
let(:test_routes) do
[
'GET / TestApp.index',
'GET /show/:id TestApp.show',
'POST /create TestApp.create',
'PUT /update/:id TestApp.update',
'DELETE /de... |
github | delano/otto | https://github.com/delano/otto | spec/otto/auth_config_sharing_spec.rb | Ruby | mit | 19 | main | 7,576 | # spec/otto/auth_config_sharing_spec.rb
#
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Auth Config Sharing' do
let(:otto) { Otto.new }
let(:test_strategy) { double('TestStrategy') }
let(:admin_strategy) { double('AdminStrategy') }
describe 'auth config synchronization between Otto and ... |
github | delano/otto | https://github.com/delano/otto | spec/otto/backtrace_sanitization_spec.rb | Ruby | mit | 19 | main | 6,542 | # frozen_string_literal: true
require 'spec_helper'
require 'otto/logging_helpers'
RSpec.describe 'Otto::LoggingHelpers backtrace sanitization' do
let(:project_root) { '/Users/alice/projects/myapp' }
describe '.sanitize_backtrace_line' do
it 'converts project files to relative paths' do
line = '/Users/... |
github | delano/otto | https://github.com/delano/otto | spec/otto/auth_logging_spec.rb | Ruby | mit | 19 | main | 2,808 | # spec/otto/auth_logging_spec.rb
#
# frozen_string_literal: true
require_relative '../spec_helper'
RSpec.describe 'Otto Authentication and Security Logging' do
let(:logger_double) { double('logger', debug: nil, info: nil, warn: nil, error: nil) }
before do
Otto.debug = true # Enable debug logging for tests
... |
github | delano/otto | https://github.com/delano/otto | spec/otto/response_handlers_spec.rb | Ruby | mit | 19 | main | 7,829 | # spec/otto/response_handlers_spec.rb
#
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Otto::ResponseHandlers do
describe Otto::ResponseHandlers::JSONHandler do
let(:response) { Rack::Response.new }
it 'sets JSON content type' do
Otto::ResponseHandlers::JSONHandler.handle({ messag... |
github | delano/otto | https://github.com/delano/otto | spec/otto/uri_spec.rb | Ruby | mit | 19 | main | 7,511 | # spec/otto/uri_spec.rb
#
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Otto, '#uri' do
let(:complex_routes) do
[
'GET / TestApp.index',
'GET /show/:id TestApp.show',
'GET /users/:user_id/posts/:post_id TestApp.user_post',
'GET /search TestApp.search',
'PUT /up... |
github | delano/otto | https://github.com/delano/otto | spec/otto/route_handlers_spec.rb | Ruby | mit | 19 | main | 29,915 | # spec/otto/route_handlers_spec.rb
#
# frozen_string_literal: true
require_relative '../spec_helper'
# Authentication result data class to replace OpenStruct
AuthResultData = Data.define(:session, :user) do
def initialize(session: {}, user: {})
super(session: session, user: user)
end
# Provide user_context... |
github | delano/otto | https://github.com/delano/otto | spec/otto/configuration_methods_spec.rb | Ruby | mit | 19 | main | 11,158 | # spec/otto/configuration_methods_spec.rb
#
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Otto, 'Configuration Methods' do
describe '#configure_locale' do
context 'with no locale configuration' do
it 'does not create locale_config when no options provided' do
app = Otto.new
... |
github | delano/otto | https://github.com/delano/otto | spec/otto/locale_config_spec.rb | Ruby | mit | 19 | main | 4,810 | # spec/otto/locale_config_spec.rb
#
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Otto, 'locale configuration' do
let(:available_locales) { { 'en' => 'English', 'es' => 'Spanish', 'fr' => 'French' } }
let(:default_locale) { 'en' }
describe 'initialization with direct locale options' do
... |
github | delano/otto | https://github.com/delano/otto | spec/otto/security_spec.rb | Ruby | mit | 19 | main | 4,773 | # spec/otto/security_spec.rb
#
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Otto, 'security features' do
subject(:otto) { create_minimal_otto }
describe 'security header methods' do
describe '#enable_hsts!' do
it 'enables HSTS with default settings' do
otto.enable_hsts!
... |
github | delano/otto | https://github.com/delano/otto | spec/otto/middleware_args_edge_cases_spec.rb | Ruby | mit | 19 | main | 8,645 | # spec/otto/middleware_args_edge_cases_spec.rb
#
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Middleware Args Edge Cases' do
let(:otto) { Otto.new }
let(:security_config) { otto.security_config }
# Mock middleware classes for testing
let(:security_middleware) do
Class.new do
... |
github | delano/otto | https://github.com/delano/otto | spec/otto/user_agent_anonymization_comprehensive_spec.rb | Ruby | mit | 19 | main | 19,577 | # spec/otto/user_agent_anonymization_comprehensive_spec.rb
#
# frozen_string_literal: true
require 'spec_helper'
require 'net/http'
require 'uri'
require 'yaml'
require 'user_agent_parser'
RSpec.describe 'Comprehensive User Agent Anonymization' do
let(:app) { ->(env) { [200, {}, ['OK']] } }
let(:security_config) ... |
github | delano/otto | https://github.com/delano/otto | spec/otto/mcp_route_parsing_spec.rb | Ruby | mit | 19 | main | 12,361 | # spec/otto/mcp_route_parsing_spec.rb
#
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Otto, 'MCP Route Parsing' do
let(:app) { Otto.new }
before do
# Mock the required MCP classes
stub_const('Otto::MCP::RouteParser', Class.new do
def self.parse_mcp_route(_verb, _path, definitio... |
github | delano/otto | https://github.com/delano/otto | spec/otto/request_helpers_spec.rb | Ruby | mit | 19 | main | 7,341 | # spec/otto/request_helpers_spec.rb
#
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Otto::Request do
let(:request_env) do
{
'REQUEST_METHOD' => 'GET',
'PATH_INFO' => '/test',
'QUERY_STRING' => '',
'HTTP_HOST' => 'example.com',
'SERVER_NAME' => 'example.com',
... |
github | delano/otto | https://github.com/delano/otto | spec/otto/request_response_helpers_spec.rb | Ruby | mit | 19 | main | 8,379 | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Otto Request/Response Helper Registration' do
let(:routes_file) { create_test_routes_file('routes_basic.txt', ['GET / TestApp.index']) }
describe 'Otto::Request' do
it 'is a subclass of Rack::Request' do
expect(Otto::Request.superclass... |
github | delano/otto | https://github.com/delano/otto | spec/otto/rate_limiting_spec.rb | Ruby | mit | 19 | main | 9,635 | # spec/otto/rate_limiting_spec.rb
#
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Otto, 'rate limiting features' do
subject(:otto) { create_minimal_otto }
before do
# Skip rate limiting tests if rack-attack is not available
skip 'rack-attack not available' unless defined?(Rack::Attac... |
github | delano/otto | https://github.com/delano/otto | spec/otto/utils_spec.rb | Ruby | mit | 19 | main | 3,224 | # spec/otto/utils_spec.rb
#
# frozen_string_literal: true
require "spec_helper"
RSpec.describe Otto::Utils do
describe "#now" do
it "returns current time in UTC" do
freeze_time = Time.parse("2023-01-01 12:00:00 UTC")
allow(Time).to receive(:now).and_return(freeze_time)
result = Otto::Utils.no... |
github | delano/otto | https://github.com/delano/otto | spec/otto/route_definition_spec.rb | Ruby | mit | 19 | main | 7,292 | # spec/otto/route_definition_spec.rb
#
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Otto::RouteDefinition do
describe '#auth_requirements' do
it 'returns empty array when auth option is not present' do
route = described_class.new('GET', '/public', 'TestApp.public')
expect(rout... |
github | delano/otto | https://github.com/delano/otto | spec/otto/ip_privacy_spec.rb | Ruby | mit | 19 | main | 71,681 | # spec/otto/ip_privacy_spec.rb
#
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'IP Privacy Features' do
describe Otto::Privacy::IPPrivacy do
describe '.mask_ip' do
context 'IPv4 addresses' do
it 'masks last octet with level 1' do
expect(Otto::Privacy::IPPrivacy.mask_... |
github | delano/otto | https://github.com/delano/otto | spec/otto/response_integration_spec.rb | Ruby | mit | 19 | main | 3,732 | # spec/otto/response_integration_spec.rb
#
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Otto, 'response handler integration' do
describe 'JSON response handling' do
let(:app) { create_minimal_otto(['GET /api/data TestApp.json_data response=json']) }
it 'automatically converts return v... |
github | delano/otto | https://github.com/delano/otto | spec/otto/middleware_stack_synchronization_spec.rb | Ruby | mit | 19 | main | 4,893 | # spec/otto/middleware_stack_synchronization_spec.rb
#
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Middleware Stack Synchronization' do
let(:otto) { Otto.new }
let(:test_middleware1) do
Class.new do
def initialize(app, *args)
@app = app
end
def call(env)
... |
github | delano/otto | https://github.com/delano/otto | spec/otto/errors_spec.rb | Ruby | mit | 19 | main | 5,484 | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Otto Error Classes' do
describe 'base error class hierarchy' do
describe 'Otto::HTTPError' do
it 'inherits from StandardError' do
expect(Otto::HTTPError.ancestors).to include(StandardError)
end
it 'defines default_sta... |
github | delano/otto | https://github.com/delano/otto | spec/otto/logging_integration_spec.rb | Ruby | mit | 19 | main | 19,053 | # spec/otto/logging_integration_spec.rb
#
# frozen_string_literal: true
require_relative '../spec_helper'
RSpec.describe 'Otto Logging Integration' do
let(:app_double) { double('app') }
let(:logger_double) { double('logger', debug: nil, info: nil, warn: nil, error: nil) }
let(:routes_content) do
<<~ROUTES
... |
github | delano/otto | https://github.com/delano/otto | spec/otto/enhanced_routing_spec.rb | Ruby | mit | 19 | main | 4,242 | # spec/otto/enhanced_routing_spec.rb
#
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Otto::Route, 'enhanced route parsing' do
describe '#initialize with enhanced parameters' do
it 'parses traditional class method routes' do
route = Otto::Route.new('GET', '/test', 'TestApp.index')
... |
github | delano/otto | https://github.com/delano/otto | spec/otto/configuration_freezing_spec.rb | Ruby | mit | 19 | main | 10,138 | # spec/otto/configuration_freezing_spec.rb
#
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Otto, 'configuration freezing' do
let(:routes_file) { create_test_routes_file('common_routes.txt', ['GET / TestApp.index']) }
describe 'automatic freezing on initialization' do
it 'skips freezing w... |
github | delano/otto | https://github.com/delano/otto | spec/otto/routing_spec.rb | Ruby | mit | 19 | main | 6,207 | # spec/otto/routing_spec.rb
#
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Otto, 'request handling and routing' do
let(:test_routes) do
[
'GET / TestApp.index',
'GET /show/:id TestApp.show',
'POST /create TestApp.create',
'PUT /update/:id TestApp.update',
'DEL... |
github | delano/otto | https://github.com/delano/otto | spec/otto/error_handling_spec.rb | Ruby | mit | 19 | main | 12,910 | # spec/otto/error_handling_spec.rb
#
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Otto, 'Error Handling' do
let(:test_app) { create_minimal_otto }
describe '#handle_error' do
let(:env) { mock_rack_env(method: 'GET', path: '/test') }
let(:error) do
err = StandardError.new('Test... |
github | delano/otto | https://github.com/delano/otto | spec/otto/file_safety_spec.rb | Ruby | mit | 19 | main | 2,356 | # spec/otto/file_safety_spec.rb
#
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Otto, 'file safety checks' do
subject(:otto) { described_class.new(nil, { public: '/tmp/test_public' }) }
before do
Dir.mkdir('/tmp/test_public') unless Dir.exist?('/tmp/test_public')
File.write('/tmp/tes... |
github | delano/otto | https://github.com/delano/otto | spec/otto/error_handler_registration_spec.rb | Ruby | mit | 19 | main | 15,850 | # spec/otto/error_handler_registration_spec.rb
#
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Otto, 'Error Handler Registration' do
# Define test error classes
class TestMissingResourceError < StandardError; end
class TestExpiredResourceError < StandardError; end
class TestRateLimitError... |
github | delano/otto | https://github.com/delano/otto | spec/otto/locale/middleware_spec.rb | Ruby | mit | 19 | main | 10,556 | # spec/otto/locale/middleware_spec.rb
#
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Otto::Locale::Middleware do
let(:inner_app) { ->(env) { [200, {}, [env['otto.locale']]] } }
let(:default_locale) { 'en' }
let(:available_locales) { { 'en' => 'English', 'es' => 'Spanish', 'fr' => 'French' ... |
github | delano/otto | https://github.com/delano/otto | spec/otto/mcp/rate_limiting_spec.rb | Ruby | mit | 19 | main | 8,874 | # spec/otto/mcp/rate_limiting_spec.rb
#
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Otto::MCP, 'rate limiting features' do
before do
skip 'rack-attack not available' unless defined?(Rack::Attack)
end
describe 'Otto::MCP::RateLimiter' do
describe '.configure_rack_attack!' do
... |
github | delano/otto | https://github.com/delano/otto | spec/otto/core/middleware_stack_spec.rb | Ruby | mit | 19 | main | 7,046 | # spec/otto/core/middleware_stack_spec.rb
#
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Otto::Core::MiddlewareStack do
let(:stack) { described_class.new }
let(:test_middleware1) { Class.new }
let(:test_middleware2) { Class.new }
let(:test_middleware3) { Class.new }
describe '#add' do... |
github | delano/otto | https://github.com/delano/otto | spec/otto/security/configurator_spec.rb | Ruby | mit | 19 | main | 9,591 | # spec/otto/security/configurator_spec.rb
#
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Otto::Security::Configurator do
let(:security_config) { Otto::Security::Config.new }
let(:middleware_stack) { Otto::Core::MiddlewareStack.new }
let(:configurator) { described_class.new(security_config,... |
github | delano/otto | https://github.com/delano/otto | spec/otto/security/route_auth_wrapper_spec.rb | Ruby | mit | 19 | main | 42,531 | # spec/otto/security/route_auth_wrapper_spec.rb
#
# frozen_string_literal: true
require 'spec_helper'
require 'delegate'
RSpec.describe Otto::Security::Authentication::RouteAuthWrapper do
include OttoTestHelpers
let(:mock_handler) do
lambda do |env, _extra_params|
[200, { 'Content-Type' => 'text/plain'... |
github | delano/otto | https://github.com/delano/otto | lib/otto.rb | Ruby | mit | 19 | main | 9,705 | # lib/otto.rb
#
# frozen_string_literal: true
require 'json'
require 'logger'
require 'securerandom'
require 'uri'
require 'rack/request'
require 'rack/response'
require 'rack/utils'
require_relative 'otto/request'
require_relative 'otto/response'
require_relative 'otto/route_definition'
require_relative 'otto/route... |
github | delano/otto | https://github.com/delano/otto | lib/otto/logging_helpers.rb | Ruby | mit | 19 | main | 10,654 | # lib/otto/logging_helpers.rb
#
# frozen_string_literal: true
class Otto
# LoggingHelpers provides utility methods for consistent structured logging
# across the Otto framework. Centralizes common request context extraction
# to eliminate duplication while keeping logging calls simple and explicit.
module Logg... |
github | delano/otto | https://github.com/delano/otto | lib/otto/static.rb | Ruby | mit | 19 | main | 1,365 | # lib/otto/static.rb
#
# frozen_string_literal: true
class Otto
# Static response utilities for common HTTP responses
module Static
extend self
def server_error
[500, security_headers.merge({ 'content-type' => 'text/plain' }), ['Server error']]
end
def not_found
[404, security_headers... |
github | delano/otto | https://github.com/delano/otto | lib/otto/design_system.rb | Ruby | mit | 19 | main | 14,603 | # lib/otto/design_system.rb
#
# frozen_string_literal: true
class Otto
# Shared design system for Otto framework examples
# Provides consistent styling, components, and utilities
module DesignSystem
def otto_page(content, title = 'Otto Framework', additional_head = '')
<<~HTML
<!DOCTYPE html>
... |
github | delano/otto | https://github.com/delano/otto | lib/otto/route_handlers.rb | Ruby | mit | 19 | main | 517 | # lib/otto/route_handlers.rb
#
# frozen_string_literal: true
class Otto
# Pluggable Route Handler Factory
#
# Enables different execution patterns while maintaining backward compatibility
module RouteHandlers
require_relative 'route_handlers/base'
require_relative 'route_handlers/factory'
require_r... |
github | delano/otto | https://github.com/delano/otto | lib/otto/response_handlers.rb | Ruby | mit | 19 | main | 444 | # lib/otto/response_handlers.rb
#
# frozen_string_literal: true
class Otto
module ResponseHandlers
require_relative 'response_handlers/base'
require_relative 'response_handlers/json'
require_relative 'response_handlers/redirect'
require_relative 'response_handlers/view'
require_relative 'response... |
github | delano/otto | https://github.com/delano/otto | lib/otto/helpers.rb | Ruby | mit | 19 | main | 218 | # lib/otto/helpers.rb
#
# frozen_string_literal: true
# Request and response helpers are now defined directly in Otto::Request and Otto::Response
# This file is kept for backward compatibility with require statements |
github | delano/otto | https://github.com/delano/otto | lib/otto/route_definition.rb | Ruby | mit | 19 | main | 6,447 | # lib/otto/route_definition.rb
#
# frozen_string_literal: true
class Otto
# Immutable data class representing a complete route definition
# This encapsulates all aspects of a route: path, target, and options
class RouteDefinition
# @return [String] The HTTP verb (GET, POST, etc.)
attr_reader :verb
#... |
github | delano/otto | https://github.com/delano/otto | lib/otto/route.rb | Ruby | mit | 19 | main | 8,011 | # lib/otto/route.rb
#
# frozen_string_literal: true
class Otto
# Otto::Route
#
# A Route is a definition of a URL path and the method to call when
# that path is requested. Each route represents a single line in a
# routes file.
#
# Routes include built-in security features:
# - Class name validation t... |
github | delano/otto | https://github.com/delano/otto | lib/otto/request.rb | Ruby | mit | 19 | main | 16,453 | # lib/otto/request.rb
#
# frozen_string_literal: true
require 'rack/request'
class Otto
# Otto's enhanced Rack::Request class with built-in helpers
#
# This class extends Rack::Request with Otto's framework helpers for
# HTTP request handling, privacy, security, and locale management.
# Projects can registe... |
github | delano/otto | https://github.com/delano/otto | lib/otto/security.rb | Ruby | mit | 19 | main | 510 | # lib/otto/security.rb
#
# frozen_string_literal: true
require_relative 'security/core'
require_relative 'security/authentication/strategy_result'
require_relative 'security/authorization_error'
require_relative 'security/config'
require_relative 'security/configurator'
require_relative 'security/middleware/csrf_middl... |
github | delano/otto | https://github.com/delano/otto | lib/otto/utils.rb | Ruby | mit | 19 | main | 999 | # lib/otto/utils.rb
#
# frozen_string_literal: true
class Otto
# Utility methods for common operations and helpers
module Utils
extend self
# @return [Time] Current time in UTC
def now
Time.now.utc
end
# Returns the current time in microseconds.
# This is used to measure the duratio... |
github | delano/otto | https://github.com/delano/otto | lib/otto/privacy.rb | Ruby | mit | 19 | main | 1,034 | # lib/otto/privacy.rb
#
# frozen_string_literal: true
require_relative 'privacy/core'
require_relative 'privacy/config'
require_relative 'privacy/ip_privacy'
require_relative 'privacy/geo_resolver'
require_relative 'privacy/redacted_fingerprint'
# Otto::Privacy module provides IP address anonymization and privacy fea... |
github | delano/otto | https://github.com/delano/otto | lib/otto/env_keys.rb | Ruby | mit | 19 | main | 6,635 | # lib/otto/env_keys.rb
#
# frozen_string_literal: true
#
# Central registry of all env['otto.*'] keys used throughout Otto framework.
# This documentation helps prevent key conflicts and aids multi-app integration.
#
# DOCUMENTATION-ONLY MODULE: The constants defined here are intentionally NOT used
# in the codebase. O... |
github | delano/otto | https://github.com/delano/otto | lib/otto/errors.rb | Ruby | mit | 19 | main | 1,918 | # frozen_string_literal: true
# Base error classes for Otto framework
#
# These classes provide a foundation for HTTP error handling and can be
# subclassed by implementing projects for consistent error handling.
#
# @example Subclassing in an application
# class MyApp::ResourceNotFound < Otto::NotFoundError; end
#
... |
github | delano/otto | https://github.com/delano/otto | lib/otto/response.rb | Ruby | mit | 19 | main | 6,487 | # lib/otto/response.rb
#
# frozen_string_literal: true
require 'rack/response'
class Otto
# Otto's enhanced Rack::Response class with built-in helpers
#
# This class extends Rack::Response with Otto's framework helpers for
# HTTP response handling, cookie management, CSP headers, and security.
# Projects ca... |
github | delano/otto | https://github.com/delano/otto | lib/otto/core.rb | Ruby | mit | 19 | main | 400 | # lib/otto/core.rb
#
# frozen_string_literal: true
require_relative 'core/router'
require_relative 'core/file_safety'
require_relative 'core/configuration'
require_relative 'core/error_handler'
require_relative 'core/uri_generator'
require_relative 'core/middleware_stack'
require_relative 'core/helper_registry'
requir... |
github | delano/otto | https://github.com/delano/otto | lib/otto/security/validator.rb | Ruby | mit | 19 | main | 358 | # lib/otto/security/validator.rb
#
# frozen_string_literal: true
#
# Index file for validation middleware
# Provides backward compatibility for existing validation usage
require_relative 'middleware/validation_middleware'
class Otto
module Security
# Backward compatibility alias
ValidationMiddleware = Middl... |
github | delano/otto | https://github.com/delano/otto | lib/otto/security/authentication.rb | Ruby | mit | 19 | main | 1,356 | # lib/otto/security/authentication.rb
#
# frozen_string_literal: true
#
# Index file for Otto authentication module
# Requires all authentication-related components for backward compatibility
require_relative 'authentication/auth_strategy'
require_relative 'authentication/strategy_result'
require_relative 'authenticat... |
github | delano/otto | https://github.com/delano/otto | lib/otto/security/authorization_error.rb | Ruby | mit | 19 | main | 2,589 | # lib/otto/security/authorization_error.rb
#
# frozen_string_literal: true
class Otto
module Security
# Authorization error for resource-level access control failures
#
# This exception is designed to be raised from Logic classes when a user
# attempts to access a resource they don't have permission ... |
github | delano/otto | https://github.com/delano/otto | lib/otto/security/config.rb | Ruby | mit | 19 | main | 17,148 | # lib/otto/security/config.rb
#
# frozen_string_literal: true
require 'securerandom'
require 'digest'
require_relative '../core/freezable'
class Otto
module Security
# Security configuration for Otto applications
#
# This class manages all security-related settings including CSRF protection,
# input... |
github | delano/otto | https://github.com/delano/otto | lib/otto/security/configurator.rb | Ruby | mit | 19 | main | 9,867 | # lib/otto/security/configurator.rb
#
# frozen_string_literal: true
require_relative 'middleware/csrf_middleware'
require_relative 'middleware/validation_middleware'
require_relative 'middleware/rate_limit_middleware'
# Security configuration facade for Otto framework
class Otto
module Security
# Consolidates a... |
github | delano/otto | https://github.com/delano/otto | lib/otto/security/rate_limiting.rb | Ruby | mit | 19 | main | 398 | # lib/otto/security/rate_limiting.rb
#
# frozen_string_literal: true
#
# Index file for rate limiting components
# Provides backward compatibility for existing rate limiting usage
require_relative 'rate_limiter'
require_relative 'middleware/rate_limit_middleware'
class Otto
module Security
# Backward compatibil... |
github | delano/otto | https://github.com/delano/otto | lib/otto/security/rate_limiter.rb | Ruby | mit | 19 | main | 3,122 | # lib/otto/security/rate_limiter.rb
#
# frozen_string_literal: true
require 'json'
begin
require 'rack/attack'
rescue LoadError
# rack-attack is optional - graceful fallback
end
class Otto
module Security
# Rate limiting implementation using Rack::Attack
class RateLimiting
def self.configure_rack... |
github | delano/otto | https://github.com/delano/otto | lib/otto/security/csrf.rb | Ruby | mit | 19 | main | 1,104 | # lib/otto/security/csrf.rb
#
# frozen_string_literal: true
#
# Index file for CSRF protection components
# Provides backward compatibility for existing CSRF usage
require_relative 'middleware/csrf_middleware'
class Otto
module Security
# Backward compatibility alias
CSRFMiddleware = Middleware::CSRFMiddlew... |
github | delano/otto | https://github.com/delano/otto | lib/otto/security/core.rb | Ruby | mit | 19 | main | 7,117 | # lib/otto/security/core.rb
#
# frozen_string_literal: true
class Otto
module Security
# Core security configuration methods included in the Otto class.
# Provides the public API for enabling and configuring security features.
module Core
# Enable CSRF protection for POST, PUT, DELETE, and PATCH re... |
github | delano/otto | https://github.com/delano/otto | lib/otto/security/middleware/validation_middleware.rb | Ruby | mit | 19 | main | 9,106 | # lib/otto/security/middleware/validation_middleware.rb
#
# frozen_string_literal: true
require_relative '../config'
require_relative '../../helpers/validation'
class Otto
module Security
module Middleware
# ValidationMiddleware provides input validation and sanitization for web requests
# Uses Loof... |
github | delano/otto | https://github.com/delano/otto | lib/otto/security/middleware/ip_privacy_middleware.rb | Ruby | mit | 19 | main | 9,245 | # lib/otto/security/middleware/ip_privacy_middleware.rb
#
# frozen_string_literal: true
class Otto
module Security
module Middleware
# IP Privacy Middleware
#
# Automatically masks IP addresses for privacy by default. Original IPs
# are never stored unless privacy is explicitly disabled.
... |
github | delano/otto | https://github.com/delano/otto | lib/otto/security/middleware/rate_limit_middleware.rb | Ruby | mit | 19 | main | 1,834 | # lib/otto/security/middleware/rate_limit_middleware.rb
#
# frozen_string_literal: true
require_relative '../rate_limiter'
class Otto
module Security
module Middleware
# Middleware for applying rate limiting to HTTP requests
class RateLimitMiddleware
# NOTE: This middleware is a CONFIGURATOR... |
github | delano/otto | https://github.com/delano/otto | lib/otto/security/middleware/csrf_middleware.rb | Ruby | mit | 19 | main | 5,336 | # lib/otto/security/middleware/csrf_middleware.rb
#
# frozen_string_literal: true
require_relative '../config'
class Otto
module Security
module Middleware
# Middleware that provides Cross-Site Request Forgery (CSRF) protection
class CSRFMiddleware
SAFE_METHODS = %w[GET HEAD OPTIONS TRACE].f... |
github | delano/otto | https://github.com/delano/otto | lib/otto/security/authentication/route_auth_wrapper.rb | Ruby | mit | 19 | main | 10,716 | # frozen_string_literal: true
require_relative 'route_auth_wrapper/strategy_resolver'
require_relative 'route_auth_wrapper/response_builder'
require_relative 'route_auth_wrapper/role_authorization'
class Otto
module Security
module Authentication
# Wraps route handlers with authentication and authorizatio... |
github | delano/otto | https://github.com/delano/otto | lib/otto/security/authentication/auth_strategy.rb | Ruby | mit | 19 | main | 2,061 | # lib/otto/security/authentication/auth_strategy.rb
#
# frozen_string_literal: true
# Base class for all authentication strategies in Otto framework
# Provides pluggable authentication patterns that can be customized per application
class Otto
module Security
module Authentication
# Base class for all aut... |
github | delano/otto | https://github.com/delano/otto | lib/otto/security/authentication/auth_failure.rb | Ruby | mit | 19 | main | 1,193 | # lib/otto/security/authentication/auth_failure.rb
#
# frozen_string_literal: true
class Otto
module Security
module Authentication
# Failure result for authentication failures
AuthFailure = Data.define(:failure_reason, :auth_method) do
# AuthFailure represents authentication failure
... |
github | delano/otto | https://github.com/delano/otto | lib/otto/security/authentication/strategy_result.rb | Ruby | mit | 19 | main | 12,275 | # lib/otto/security/authentication/strategy_result.rb
#
# frozen_string_literal: true
# StrategyResult is an immutable data structure that holds the result of an
# authentication strategy. It contains session, user, and metadata needed by
# Otto Logic classes.
#
# @example Basic usage
# result = StrategyResult.new(
... |
github | delano/otto | https://github.com/delano/otto | lib/otto/security/authentication/route_auth_wrapper/response_builder.rb | Ruby | mit | 19 | main | 4,614 | # frozen_string_literal: true
class Otto
module Security
module Authentication
module RouteAuthWrapperComponents
# Builds HTTP error responses for authentication/authorization failures
#
# Handles content negotiation (JSON vs HTML) and applies security headers.
# Route's dec... |
github | delano/otto | https://github.com/delano/otto | lib/otto/security/authentication/route_auth_wrapper/strategy_resolver.rb | Ruby | mit | 19 | main | 2,399 | # frozen_string_literal: true
class Otto
module Security
module Authentication
module RouteAuthWrapperComponents
# Resolves authentication strategy names to strategy instances
#
# Handles strategy lookup with caching and pattern matching:
# - Exact match: 'authenticated' → l... |
github | delano/otto | https://github.com/delano/otto | lib/otto/security/authentication/route_auth_wrapper/role_authorization.rb | Ruby | mit | 19 | main | 4,455 | # frozen_string_literal: true
class Otto
module Security
module Authentication
module RouteAuthWrapperComponents
# Handles Layer 1 (route-level) role-based authorization
#
# Extracts user roles from authentication results and checks against
# route requirements using OR logi... |
github | delano/otto | https://github.com/delano/otto | lib/otto/security/authentication/strategies/api_key_strategy.rb | Ruby | mit | 19 | main | 1,264 | # lib/otto/security/authentication/strategies/api_key_strategy.rb
#
# frozen_string_literal: true
require_relative '../auth_strategy'
class Otto
module Security
module Authentication
module Strategies
# API key authentication strategy
class APIKeyStrategy < AuthStrategy
def initi... |
github | delano/otto | https://github.com/delano/otto | lib/otto/security/authentication/strategies/noauth_strategy.rb | Ruby | mit | 19 | main | 759 | # lib/otto/security/authentication/strategies/noauth_strategy.rb
#
# frozen_string_literal: true
require_relative '../auth_strategy'
require_relative '../strategy_result'
class Otto
module Security
module Authentication
module Strategies
# Public access strategy - always allows access
clas... |
github | delano/otto | https://github.com/delano/otto | lib/otto/security/authentication/strategies/session_strategy.rb | Ruby | mit | 19 | main | 1,235 | # lib/otto/security/authentication/strategies/session_strategy.rb
#
# frozen_string_literal: true
require_relative '../auth_strategy'
class Otto
module Security
module Authentication
module Strategies
# Session-based authentication strategy
class SessionStrategy < AuthStrategy
de... |
github | delano/otto | https://github.com/delano/otto | lib/otto/security/authentication/strategies/role_strategy.rb | Ruby | mit | 19 | main | 2,069 | # lib/otto/security/authentication/strategies/role_strategy.rb
#
# frozen_string_literal: true
require_relative '../auth_strategy'
class Otto
module Security
module Authentication
module Strategies
# Role-based authentication strategy
class RoleStrategy < AuthStrategy
def initial... |
github | delano/otto | https://github.com/delano/otto | lib/otto/security/authentication/strategies/permission_strategy.rb | Ruby | mit | 19 | main | 1,669 | # lib/otto/security/authentication/strategies/permission_strategy.rb
#
# frozen_string_literal: true
require_relative '../auth_strategy'
class Otto
module Security
module Authentication
module Strategies
# Permission-based authentication strategy
class PermissionStrategy < AuthStrategy
... |
github | delano/otto | https://github.com/delano/otto | lib/otto/response_handlers/factory.rb | Ruby | mit | 19 | main | 1,108 | # lib/otto/response_handlers/factory.rb
#
# frozen_string_literal: true
require_relative 'json'
require_relative 'redirect'
require_relative 'view'
require_relative 'auto'
require_relative 'default'
class Otto
module ResponseHandlers
# Factory for creating response handlers
class HandlerFactory
# Map ... |
github | delano/otto | https://github.com/delano/otto | lib/otto/response_handlers/base.rb | Ruby | mit | 19 | main | 486 | # lib/otto/response_handlers/base.rb
#
# frozen_string_literal: true
class Otto
module ResponseHandlers
# Base response handler class
class BaseHandler
def self.handle(result, response, context = {})
raise NotImplementedError, 'Subclasses must implement handle method'
end
def self.... |
github | delano/otto | https://github.com/delano/otto | lib/otto/response_handlers/default.rb | Ruby | mit | 19 | main | 503 | # lib/otto/response_handlers/default.rb
#
# frozen_string_literal: true
require_relative 'base'
class Otto
module ResponseHandlers
# Default handler that preserves existing Otto behavior
class DefaultHandler < BaseHandler
def self.handle(_result, response, _context = {})
# Otto's default behav... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.