Skip to content
Snippets Groups Projects
Commit c981f1c7 authored by Pam Artiaga's avatar Pam Artiaga :three: Committed by Vitali Tatarintev
Browse files

Use `AgentTokensFinder` to find single agent tokens

parent a986341a
No related branches found
No related tags found
1 merge request!103292Use `AgentTokensFinder` to find single agent tokens
......@@ -2,6 +2,8 @@
module Clusters
class AgentTokensFinder
include FinderMethods
def initialize(agent, current_user)
@agent = agent
@current_user = current_user
......
......@@ -25,5 +25,9 @@ class AgentToken < ApplicationRecord
active: 0,
revoked: 1
}
def to_ability_name
:cluster
end
end
end
......@@ -43,8 +43,7 @@ class AgentTokens < ::API::Base
end
get ':token_id' do
agent = ::Clusters::AgentsFinder.new(user_project, current_user).find(params[:agent_id])
token = agent.agent_tokens.find(params[:token_id])
token = ::Clusters::AgentTokensFinder.new(agent, current_user).find(params[:token_id])
present token, with: Entities::Clusters::AgentToken
end
......
......@@ -49,4 +49,12 @@
expect(agent_token.token.length).to be >= 50
end
end
describe '#to_ability_name' do
it 'is :cluster' do
agent_token = build(:cluster_agent_token)
expect(agent_token.to_ability_name).to eq :cluster
end
end
end
......@@ -80,6 +80,27 @@
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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment