Skip to content

Commit 0570eed

Browse files
committed
More tests for IdentityToken
1 parent 26a5eaf commit 0570eed

File tree

1 file changed

+41
-4
lines changed

1 file changed

+41
-4
lines changed

spec/layer/identity_token_spec.rb

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
nonce = "your_random_nonce"
88
expires_at = "12345678"
99

10-
# layer = Layer::Api::Client.new
1110
token = Layer::Api::IdentityToken.new(
1211
user_id: user_id,
1312
nonce: nonce,
@@ -34,21 +33,59 @@
3433
end
3534
end
3635

37-
describe ".get_jwt" do
38-
end
39-
4036
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
4146
end
4247

4348
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
4463
end
4564

4665
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
4770
end
4871

4972
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
5077
end
5178

5279
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
5390
end
5491
end

0 commit comments

Comments
 (0)