Module: Rack::Firebase::TestHelpers
- Defined in:
- lib/rack/firebase/test_helpers.rb
Class Method Summary collapse
- .auth_headers(headers, uid, aud: nil, options: {}) ⇒ Object
- .mock_end ⇒ Object
- .mock_signature_verification ⇒ Object
- .mock_start(expires_in = 5000) ⇒ Object
- .secret_key ⇒ Object
Class Method Details
.auth_headers(headers, uid, aud: nil, options: {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/rack/firebase/test_helpers.rb', line 4 def self.auth_headers(headers, uid, aud: nil, options: {}) cached_current_time = Time.now.to_i aud ||= Rack::Firebase.configuration.project_ids.first payload = { iss: "https://securetoken.google.com/#{aud}", aud: aud, auth_time: [:auth_time] || [:iat] || cached_current_time, user_id: uid, sub: uid, iat: [:iat] || cached_current_time, exp: [:exp] || cached_current_time + 5000, email: [:email] || "[email protected]", email_verified: !![:verified], firebase: { identities: { email: [ [:email], "[email protected]" ] }, sign_in_provider: "password" } } token = JWT.encode(payload, secret_key, Rack::Firebase::ALG, kid: "1234567890") headers = headers.dup headers["Authorization"] = "Bearer #{token}" headers end |
.mock_end ⇒ Object
45 46 47 48 |
# File 'lib/rack/firebase/test_helpers.rb', line 45 def self.mock_end Rack::Firebase.instance_variable_set(:@cached_keys, nil) Rack::Firebase.instance_variable_set(:@refresh_cache_by, nil) end |
.mock_signature_verification ⇒ Object
39 40 41 42 43 |
# File 'lib/rack/firebase/test_helpers.rb', line 39 def self.mock_signature_verification mock_start yield mock_end end |
.mock_start(expires_in = 5000) ⇒ Object
34 35 36 37 |
# File 'lib/rack/firebase/test_helpers.rb', line 34 def self.mock_start(expires_in = 5000) Rack::Firebase.instance_variable_set(:@cached_keys, [JWT::JWK::RSA.new(secret_key.public_key, kid: "1234567890")]) Rack::Firebase.instance_variable_set(:@refresh_cache_by, Time.now.to_i + expires_in) end |
.secret_key ⇒ Object
52 53 54 |
# File 'lib/rack/firebase/test_helpers.rb', line 52 def self.secret_key @secret_key ||= OpenSSL::PKey::RSA.generate(2048) end |