|
7 | 7 | nonce = "your_random_nonce" |
8 | 8 | expires_at = "12345678" |
9 | 9 |
|
10 | | - # layer = Layer::Api::Client.new |
11 | 10 | token = Layer::Api::IdentityToken.new( |
12 | 11 | user_id: user_id, |
13 | 12 | nonce: nonce, |
|
34 | 33 | end |
35 | 34 | end |
36 | 35 |
|
37 | | - describe ".get_jwt" do |
38 | | - end |
39 | | - |
40 | 36 | describe ".headers" do |
| 37 | + it "should return necessary headers" do |
| 38 | + token = Layer::Api::IdentityToken.new |
| 39 | + |
| 40 | + headers = token.send(:headers) |
| 41 | + |
| 42 | + expect(headers[:kid]).to eq(ENV['LAYER_KEY_ID']) |
| 43 | + expect(headers[:cty]).to eq('layer-eit;v=1') |
| 44 | + expect(headers[:typ]).to eq('JWT') |
| 45 | + end |
41 | 46 | end |
42 | 47 |
|
43 | 48 | describe ".claim" do |
| 49 | + it "should return necessary payload" do |
| 50 | + token = Layer::Api::IdentityToken.new( |
| 51 | + user_id: "user_id", |
| 52 | + nonce: "nonce", |
| 53 | + expires_at: 1234567 |
| 54 | + ) |
| 55 | + |
| 56 | + claim = token.send(:claim) |
| 57 | + |
| 58 | + expect(claim[:iss]).to eq(token.layer_provider_id) |
| 59 | + expect(claim[:prn]).to eq(token.user_id) |
| 60 | + expect(claim[:exp]).to eq(token.expires_at) |
| 61 | + expect(claim[:nce]).to eq(token.nonce) |
| 62 | + end |
44 | 63 | end |
45 | 64 |
|
46 | 65 | describe ".private_key" do |
| 66 | + it "should return valid rsa private key" do |
| 67 | + key = Layer::Api::IdentityToken.new.send(:private_key) |
| 68 | + expect(key).to be_instance_of(OpenSSL::PKey::RSA) |
| 69 | + end |
47 | 70 | end |
48 | 71 |
|
49 | 72 | describe ".to_s" do |
| 73 | + it "should return a string representation of the identity token" do |
| 74 | + token = Layer::Api::IdentityToken.new.to_s |
| 75 | + expect(token).to be_instance_of(String) |
| 76 | + end |
50 | 77 | end |
51 | 78 |
|
52 | 79 | describe ".generate_identity_token" do |
| 80 | + it "should return the correct IdentityToken" do |
| 81 | + options = {} |
| 82 | + options[:user_id] = "user_id" |
| 83 | + options[:nonce] = "user_id" |
| 84 | + layer = Layer::Api::Client.new |
| 85 | + expected_token = Layer::Api::IdentityToken.new(options).to_s |
| 86 | + actual_token = layer.generate_identity_token(options) |
| 87 | + |
| 88 | + expect(actual_token).to eq(expected_token) |
| 89 | + end |
53 | 90 | end |
54 | 91 | end |
0 commit comments