Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/terraform_registry_token_spec.rb')
-rw-r--r--spec/lib/gitlab/terraform_registry_token_spec.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/spec/lib/gitlab/terraform_registry_token_spec.rb b/spec/lib/gitlab/terraform_registry_token_spec.rb
new file mode 100644
index 00000000000..49c1c07e942
--- /dev/null
+++ b/spec/lib/gitlab/terraform_registry_token_spec.rb
@@ -0,0 +1,41 @@
+# frozen_string_literal: true
+require 'spec_helper'
+
+RSpec.describe Gitlab::TerraformRegistryToken do
+ let_it_be(:user) { create(:user) }
+
+ describe '.from_token' do
+ let(:jwt_token) { described_class.from_token(token) }
+
+ subject { described_class.decode(jwt_token.encoded) }
+
+ context 'with a deploy token' do
+ let(:deploy_token) { create(:deploy_token, username: 'deployer') }
+ let(:token) { deploy_token }
+
+ it 'returns the correct token' do
+ expect(subject['token']).to eq jwt_token['token']
+ end
+ end
+
+ context 'with a job' do
+ let_it_be(:job) { create(:ci_build) }
+
+ let(:token) { job }
+
+ it 'returns the correct token' do
+ expect(subject['token']).to eq jwt_token['token']
+ end
+ end
+
+ context 'with a personal access token' do
+ let(:token) { create(:personal_access_token) }
+
+ it 'returns the correct token' do
+ expect(subject['token']).to eq jwt_token['token']
+ end
+ end
+ end
+
+ it_behaves_like 'a gitlab jwt token'
+end