summaryrefslogtreecommitdiff
path: root/spec/lib
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-05-09 22:06:32 +0300
committerKamil Trzcinski <ayufan@ayufan.eu>2016-05-09 22:06:32 +0300
commitc78b97df0eb275415d6ed5ef297841ee2f61b473 (patch)
tree583faf00aedc45eb10e0f40b6c9ffd197672cf68 /spec/lib
parentb180d79cdca2ce0f6aa7425baf47db5b9c1ec2e3 (diff)
downloadgitlab-ce-c78b97df0eb275415d6ed5ef297841ee2f61b473.tar.gz
Added rspec for testing container registry authentication service
Diffstat (limited to 'spec/lib')
-rw-r--r--spec/lib/jwt/rsa_token_spec.rb31
-rw-r--r--spec/lib/jwt/token_spec.rb18
2 files changed, 49 insertions, 0 deletions
diff --git a/spec/lib/jwt/rsa_token_spec.rb b/spec/lib/jwt/rsa_token_spec.rb
new file mode 100644
index 00000000000..710801923e7
--- /dev/null
+++ b/spec/lib/jwt/rsa_token_spec.rb
@@ -0,0 +1,31 @@
+describe Jwt::RSAToken do
+ let(:rsa_key) { generate_key }
+ let(:rsa_token) { described_class.new(nil) }
+ let(:rsa_encoded) { rsa_token.encoded }
+
+ before { allow_any_instance_of(described_class).to receive(:key).and_return(rsa_key) }
+
+ context 'token' do
+ context 'for valid key to be validated' do
+ before { rsa_token['key'] = 'value' }
+
+ subject { JWT.decode(rsa_encoded, rsa_key) }
+
+ it { expect{subject}.to_not raise_error }
+ it { expect(subject.first).to include('key' => 'value') }
+ end
+
+ context 'for invalid key to raise an exception' do
+ let(:new_key) { generate_key }
+ subject { JWT.decode(rsa_encoded, new_key) }
+
+ it { expect{subject}.to raise_error(JWT::DecodeError) }
+ end
+ end
+
+ private
+
+ def generate_key
+ OpenSSL::PKey::RSA.generate(512)
+ end
+end
diff --git a/spec/lib/jwt/token_spec.rb b/spec/lib/jwt/token_spec.rb
new file mode 100644
index 00000000000..a56b4cf39b5
--- /dev/null
+++ b/spec/lib/jwt/token_spec.rb
@@ -0,0 +1,18 @@
+describe Jwt::Token do
+ let(:token) { described_class.new }
+
+ context 'custom parameters' do
+ let(:value) { 'value' }
+ before { token[:key] = value }
+
+ it { expect(token[:key]).to eq(value) }
+ it { expect(token.payload).to include(key: value) }
+ end
+
+ context 'embeds default payload' do
+ subject { token.payload }
+ let(:default) { token.send(:default_payload) }
+
+ it { is_expected.to include(default) }
+ end
+end