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/requests/api/clusters/agent_tokens_spec.rb')
-rw-r--r--spec/requests/api/clusters/agent_tokens_spec.rb38
1 files changed, 37 insertions, 1 deletions
diff --git a/spec/requests/api/clusters/agent_tokens_spec.rb b/spec/requests/api/clusters/agent_tokens_spec.rb
index a33bef53b14..b2d996e8002 100644
--- a/spec/requests/api/clusters/agent_tokens_spec.rb
+++ b/spec/requests/api/clusters/agent_tokens_spec.rb
@@ -2,7 +2,7 @@
require 'spec_helper'
-RSpec.describe API::Clusters::AgentTokens do
+RSpec.describe API::Clusters::AgentTokens, feature_category: :kubernetes_management do
let_it_be(:agent) { create(:cluster_agent) }
let_it_be(:agent_token_one) { create(:cluster_agent_token, agent: agent) }
let_it_be(:revoked_agent_token) { create(:cluster_agent_token, :revoked, agent: agent) }
@@ -80,6 +80,27 @@ RSpec.describe API::Clusters::AgentTokens do
end
end
+ it 'returns an agent token that is revoked' do
+ get api("/projects/#{project.id}/cluster_agents/#{agent.id}/tokens/#{revoked_agent_token.id}", user)
+
+ aggregate_failures "testing response" do
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(response).to match_response_schema('public_api/v4/agent_token')
+ expect(json_response['id']).to eq(revoked_agent_token.id)
+ expect(json_response['name']).to eq(revoked_agent_token.name)
+ expect(json_response['agent_id']).to eq(agent.id)
+ expect(json_response['status']).to eq('revoked')
+ end
+ end
+
+ it 'returns a 404 if agent does not exist' do
+ path = "/projects/#{project.id}/cluster_agents/#{non_existing_record_id}/tokens/#{non_existing_record_id}"
+
+ get api(path, user)
+
+ expect(response).to have_gitlab_http_status(:not_found)
+ end
+
it 'returns a 404 error if agent token id is not available' do
get api("/projects/#{project.id}/cluster_agents/#{agent.id}/tokens/#{non_existing_record_id}", user)
@@ -160,6 +181,21 @@ RSpec.describe API::Clusters::AgentTokens do
expect(agent_token_one.reload).to be_revoked
end
+ it 'returns a success response when revoking an already revoked agent token', :aggregate_failures do
+ delete api("/projects/#{project.id}/cluster_agents/#{agent.id}/tokens/#{revoked_agent_token.id}", user)
+
+ expect(response).to have_gitlab_http_status(:no_content)
+ expect(revoked_agent_token.reload).to be_revoked
+ end
+
+ it 'returns a 404 error when given agent_id does not exist' do
+ path = "/projects/#{project.id}/cluster_agents/#{non_existing_record_id}/tokens/#{non_existing_record_id}"
+
+ delete api(path, user)
+
+ expect(response).to have_gitlab_http_status(:not_found)
+ end
+
it 'returns a 404 error when revoking non existent agent token' do
delete api("/projects/#{project.id}/cluster_agents/#{agent.id}/tokens/#{non_existing_record_id}", user)