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

project_archive_compare_spec.rb « repository « 3_create « api « features « specs « qa « qa - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 87faec86947a0ba0e2bf37b48298cbd663aec333 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# frozen_string_literal: true

require 'airborne'
require 'digest'

module QA
  RSpec.describe 'Create' do
    describe 'Compare archives of different user projects with the same name and check they\'re different',
      product_group: :source_code do
      include Support::API
      let(:project_name) { "project-archive-download-#{SecureRandom.hex(8)}" }

      let(:archive_types) { %w(tar.gz tar.bz2 tar zip) }

      let(:users) do
        {
          user1: { username: Runtime::Env.gitlab_qa_username_1, password: Runtime::Env.gitlab_qa_password_1 },
          user2: { username: Runtime::Env.gitlab_qa_username_2, password: Runtime::Env.gitlab_qa_password_2 }
        }
      end

      before do
        users.each do |_, user_info|
          user_info[:user] = Resource::User.fabricate_or_use(user_info[:username], user_info[:password])
          user_info[:api_client] = Runtime::API::Client.new(:gitlab, user: user_info[:user])
          user_info[:api_client].personal_access_token
          user_info[:project] = create_project(user_info[:user], user_info[:api_client], project_name)
        end
      end

      it 'download archives of each user project then check they are different', testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/347748' do
        archive_checksums = {}

        users.each do |user_key, user_info|
          archive_checksums[user_key] = {}

          archive_types.each do |type|
            archive_path = download_project_archive_via_api(user_info[:api_client], user_info[:project], type).path
            archive_checksums[user_key][type] = Digest::MD5.hexdigest(File.read(archive_path))
          end
        end

        QA::Runtime::Logger.debug("Archive checksums are #{archive_checksums}")

        expect(archive_checksums[:user1]).not_to include(archive_checksums[:user2])
      end

      def create_project(user, api_client, project_name)
        project = create(:project, name: project_name, api_client: api_client, add_name_uuid: false, personal_namespace: user.username)

        Resource::Repository::Commit.fabricate_via_api! do |commit|
          commit.project = project
          commit.add_files([{ file_path: 'README.md', content: '# This is a test project' }])
          commit.commit_message = 'Add README.md'
          commit.api_client = api_client
        end

        project
      end

      def download_project_archive_via_api(api_client, project, type = 'tar.gz')
        get_project_archive_zip = Runtime::API::Request.new(api_client, project.api_get_archive_path(type))
        project_archive_download = Support::API.get(get_project_archive_zip.url, raw_response: true)
        expect(project_archive_download.code).to eq(200)

        project_archive_download.file
      end
    end
  end
end