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:
authorGitLab Bot <gitlab-bot@gitlab.com>2023-11-03 00:10:29 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2023-11-03 00:10:29 +0300
commitfecb8ece925c48cf64969f1ecced12e4c4497706 (patch)
treea25112ce0985b27a390721109354fd89effa9b83 /spec/requests
parenteed7260f13c0a3139876e3659603f3d803e8fcd7 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/requests')
-rw-r--r--spec/requests/api/graphql/container_repository/container_repository_details_spec.rb120
-rw-r--r--spec/requests/api/users_spec.rb29
2 files changed, 138 insertions, 11 deletions
diff --git a/spec/requests/api/graphql/container_repository/container_repository_details_spec.rb b/spec/requests/api/graphql/container_repository/container_repository_details_spec.rb
index 118a11851dd..20277c7e27b 100644
--- a/spec/requests/api/graphql/container_repository/container_repository_details_spec.rb
+++ b/spec/requests/api/graphql/container_repository/container_repository_details_spec.rb
@@ -313,4 +313,124 @@ RSpec.describe 'container repository details', feature_category: :container_regi
end
it_behaves_like 'handling graphql network errors with the container registry'
+
+ context 'when list tags API is enabled', :saas do
+ before do
+ stub_container_registry_config(enabled: true)
+ allow(ContainerRegistry::GitlabApiClient).to receive(:supports_gitlab_api?).and_return(true)
+
+ allow_next_instances_of(ContainerRegistry::GitlabApiClient, nil) do |client|
+ allow(client).to receive(:tags).and_return(response_body)
+ end
+ end
+
+ let_it_be(:raw_tags_response) do
+ [
+ {
+ name: 'latest',
+ digest: 'sha256:1234567892',
+ config_digest: 'sha256:3332132331',
+ media_type: 'application/vnd.oci.image.manifest.v1+json',
+ size_bytes: 1234567892,
+ created_at: 10.minutes.ago,
+ updated_at: 10.minutes.ago
+ }
+ ]
+ end
+
+ let_it_be(:url) { URI('/gitlab/v1/repositories/group1/proj1/tags/list/?before=tag1') }
+
+ let_it_be(:response_body) do
+ {
+ pagination: { previous: { uri: url }, next: { uri: url } },
+ response_body: ::Gitlab::Json.parse(raw_tags_response.to_json)
+ }
+ end
+
+ it_behaves_like 'a working graphql query' do # OK
+ before do
+ subject
+ end
+
+ it 'matches the JSON schema' do
+ expect(container_repository_details_response).to match_schema('graphql/container_repository_details')
+ end
+ end
+
+ context 'with different permissions' do # OK
+ let_it_be(:user) { create(:user) }
+
+ let(:tags_response) { container_repository_details_response.dig('tags', 'nodes') }
+
+ where(:project_visibility, :role, :access_granted, :can_delete) do
+ :private | :maintainer | true | true
+ :private | :developer | true | true
+ :private | :reporter | true | false
+ :private | :guest | false | false
+ :private | :anonymous | false | false
+ :public | :maintainer | true | true
+ :public | :developer | true | true
+ :public | :reporter | true | false
+ :public | :guest | true | false
+ :public | :anonymous | true | false
+ end
+
+ with_them do
+ before do
+ project.update!(visibility_level: Gitlab::VisibilityLevel.const_get(project_visibility.to_s.upcase, false))
+ project.add_member(user, role) unless role == :anonymous
+ end
+
+ it 'return the proper response' do
+ subject
+
+ if access_granted
+ expect(tags_response.size).to eq(raw_tags_response.size)
+ expect(container_repository_details_response.dig('canDelete')).to eq(can_delete)
+ else
+ expect(container_repository_details_response).to eq(nil)
+ end
+ end
+ end
+ end
+
+ context 'querying' do
+ let(:name) { 'l' }
+ let(:tags_response) { container_repository_details_response.dig('tags', 'edges') }
+ let(:variables) do
+ { id: container_repository_global_id, n: name }
+ end
+
+ let(:query) do
+ <<~GQL
+ query($id: ContainerRepositoryID!, $n: String) {
+ containerRepository(id: $id) {
+ tags(name: $n) {
+ edges {
+ node {
+ #{all_graphql_fields_for('ContainerRepositoryTag')}
+ }
+ }
+ }
+ }
+ }
+ GQL
+ end
+
+ it 'returns the tag response', :aggregate_failures do
+ subject
+
+ expect(tags_response.size).to eq(1)
+ expect(tags_response.first.dig('node', 'name')).to eq('latest')
+ end
+
+ context 'invalid filter' do
+ let(:name) { 1 }
+
+ it_behaves_like 'returning an invalid value error'
+ end
+ end
+
+ it_behaves_like 'handling graphql network errors with the container registry'
+ end
end
diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb
index 7da44266064..1abb02cd9f0 100644
--- a/spec/requests/api/users_spec.rb
+++ b/spec/requests/api/users_spec.rb
@@ -5,6 +5,7 @@ require 'spec_helper'
RSpec.describe API::Users, :aggregate_failures, feature_category: :user_profile do
include WorkhorseHelpers
include KeysetPaginationHelpers
+ include CryptoHelpers
let_it_be(:admin) { create(:admin) }
let_it_be(:user, reload: true) { create(:user, username: 'user.withdot') }
@@ -1983,17 +1984,23 @@ RSpec.describe API::Users, :aggregate_failures, feature_category: :user_profile
end
describe "PUT /user/:id/credit_card_validation" do
- let(:credit_card_validated_time) { Time.utc(2020, 1, 1) }
+ let(:network) { 'American Express' }
+ let(:holder_name) { 'John Smith' }
+ let(:last_digits) { '1111' }
let(:expiration_year) { Date.today.year + 10 }
+ let(:expiration_month) { 1 }
+ let(:expiration_date) { Date.new(expiration_year, expiration_month, -1) }
+ let(:credit_card_validated_at) { Time.utc(2020, 1, 1) }
+
let(:path) { "/user/#{user.id}/credit_card_validation" }
let(:params) do
{
- credit_card_validated_at: credit_card_validated_time,
+ credit_card_validated_at: credit_card_validated_at,
credit_card_expiration_year: expiration_year,
- credit_card_expiration_month: 1,
- credit_card_holder_name: 'John Smith',
- credit_card_type: 'AmericanExpress',
- credit_card_mask_number: '1111'
+ credit_card_expiration_month: expiration_month,
+ credit_card_holder_name: holder_name,
+ credit_card_type: network,
+ credit_card_mask_number: last_digits
}
end
@@ -2023,11 +2030,11 @@ RSpec.describe API::Users, :aggregate_failures, feature_category: :user_profile
expect(response).to have_gitlab_http_status(:ok)
expect(user.credit_card_validation).to have_attributes(
- credit_card_validated_at: credit_card_validated_time,
- expiration_date: Date.new(expiration_year, 1, 31),
- last_digits: 1111,
- network: 'AmericanExpress',
- holder_name: 'John Smith'
+ credit_card_validated_at: credit_card_validated_at,
+ network_hash: sha256(network.downcase),
+ holder_name_hash: sha256(holder_name.downcase),
+ last_digits_hash: sha256(last_digits),
+ expiration_date_hash: sha256(expiration_date.to_s)
)
end