Class: Books::FakeAuthorityClient
- Inherits:
-
Object
- Object
- Books::FakeAuthorityClient
- Defined in:
- lib/books/fake_authority_client.rb
Overview
Test class that provides a fake RPC client for books authority. Useful for tests, it provides real SSKG generation. It does not do the full suite of verification.
Instance Method Summary collapse
- #generate_sskg(req) ⇒ Object
- #https_rpc(rpc, req) ⇒ Object
-
#initialize(raise_on_self_register: false, raise_on_verify: false) ⇒ FakeAuthorityClient
constructor
A new instance of FakeAuthorityClient.
- #register_self(req) ⇒ Object
- #verify_book(req) ⇒ Object
Constructor Details
#initialize(raise_on_self_register: false, raise_on_verify: false) ⇒ FakeAuthorityClient
Returns a new instance of FakeAuthorityClient.
10 11 12 13 14 15 |
# File 'lib/books/fake_authority_client.rb', line 10 def initialize( raise_on_self_register:false, raise_on_verify:false) @sskgs = {} @raise_on_self_register = raise_on_self_register end |
Instance Method Details
#generate_sskg(req) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/books/fake_authority_client.rb', line 38 def generate_sskg(req) { root_sskg_token: Base64.decode64("gqhwb3NpdGlvbgClbm9kZXORgqVzdGF0ZcQg/z6NXBXEZRXi1qKfcsmSmu5x2HCYgbT9ZC97IVJyqWymaGVpZ2h0Pw=="), first_key: Base64.decode64("gqhwb3NpdGlvbgGlbm9kZXOSgqVzdGF0ZcQgd1N+3oVeOJri1Jz8k0fBHSMv6YejZcT8EjW0ixZwoAOmaGVpZ2h0PoKlc3RhdGXEILIzf84dcqwznf807/8DVWJNE/Pj5MTkILqeTOOCaK3GpmhlaWdodD4="), } end |
#https_rpc(rpc, req) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/books/fake_authority_client.rb', line 17 def https_rpc(rpc, req) case rpc when :generate_sskg generate_sskg(req) when :verify_book verify_book(req) when :register_self register_self(req) else raise "Invalid RPC method #{rpc}" end end |
#register_self(req) ⇒ Object
30 31 32 |
# File 'lib/books/fake_authority_client.rb', line 30 def register_self(req) raise "Client already registered" if @raise_on_self_register end |
#verify_book(req) ⇒ Object
34 35 36 |
# File 'lib/books/fake_authority_client.rb', line 34 def verify_book(req) raise "Book has been tampered with" if @raise_on_verify end |