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

http_basic_auth_helpers.rb « helpers « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c0b24b3dfa48510f1bc9c8eb5c4b11e212a02500 (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
# frozen_string_literal: true

module HttpBasicAuthHelpers
  def user_basic_auth_header(user)
    access_token = create(:personal_access_token, user: user)

    basic_auth_header(user.username, access_token.token)
  end

  def job_basic_auth_header(job)
    basic_auth_header(Ci::Build::CI_REGISTRY_USER, job.token)
  end

  def client_basic_auth_header(client)
    basic_auth_header(client.uid, client.secret)
  end

  def basic_auth_header(username, password)
    {
      'HTTP_AUTHORIZATION' => ActionController::HttpAuthentication::Basic.encode_credentials(
        username,
        password
      )
    }
  end
end