2022-08-13 15:12:31 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe 'Query.ciVariables' do
|
|
|
|
include GraphqlHelpers
|
|
|
|
|
|
|
|
let(:query) do
|
|
|
|
%(
|
|
|
|
query {
|
|
|
|
ciVariables {
|
|
|
|
nodes {
|
|
|
|
id
|
|
|
|
key
|
|
|
|
value
|
|
|
|
variableType
|
|
|
|
protected
|
|
|
|
masked
|
|
|
|
raw
|
|
|
|
environmentScope
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the user is an admin' do
|
|
|
|
let_it_be(:user) { create(:admin) }
|
|
|
|
|
|
|
|
it "returns the instance's CI variables" do
|
|
|
|
variable = create(:ci_instance_variable, key: 'TEST_VAR', value: 'test',
|
2022-10-11 01:57:18 +05:30
|
|
|
masked: false, protected: true, raw: true)
|
2022-08-13 15:12:31 +05:30
|
|
|
|
|
|
|
post_graphql(query, current_user: user)
|
|
|
|
|
|
|
|
expect(graphql_data.dig('ciVariables', 'nodes')).to contain_exactly({
|
|
|
|
'id' => variable.to_global_id.to_s,
|
|
|
|
'key' => 'TEST_VAR',
|
|
|
|
'value' => 'test',
|
|
|
|
'variableType' => 'ENV_VAR',
|
|
|
|
'masked' => false,
|
|
|
|
'protected' => true,
|
|
|
|
'raw' => true,
|
|
|
|
'environmentScope' => nil
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the user is not an admin' do
|
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
|
|
|
|
it 'returns nothing' do
|
|
|
|
create(:ci_instance_variable, value: 'verysecret', masked: true)
|
|
|
|
|
|
|
|
post_graphql(query, current_user: user)
|
|
|
|
|
|
|
|
expect(graphql_data.dig('ciVariables')).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2022-08-27 11:52:29 +05:30
|
|
|
|
|
|
|
context 'when the user is unauthenticated' do
|
|
|
|
let_it_be(:user) { nil }
|
|
|
|
|
|
|
|
it 'returns nothing' do
|
|
|
|
create(:ci_instance_variable, value: 'verysecret', masked: true)
|
|
|
|
|
|
|
|
post_graphql(query, current_user: user)
|
|
|
|
|
|
|
|
expect(graphql_data.dig('ciVariables')).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2022-08-13 15:12:31 +05:30
|
|
|
end
|