Skip to content
Snippets Groups Projects
Commit 2b58beba authored by Zeff Morgan's avatar Zeff Morgan
Browse files

Merge branch 'qa/zm-api-cookie-update' into 'master'

Add low level api cookie passing

See merge request !83419
parents 11523c95 b83442ab
No related branches found
No related tags found
No related merge requests found
Pipeline #635958093 passed with warnings
Pipeline: GitLab

#635975549

    Pipeline: GitLab

    #635975546

      ......@@ -29,6 +29,15 @@ def gitlab_url
      @gitlab_url ||= ENV["QA_GITLAB_URL"] || "http://127.0.0.1:3000" # default to GDK
      end
      def canary_value
      # Safely retrieves the value of the gitlab_canary cookie if set or returns an empty hash.
      #
      # @return [Hash]
      canary = ENV['QA_COOKIES']&.scan(/gitlab_canary=(true|false)/)&.dig(0, 0)
      canary ? { gitlab_canary: canary } : {}
      end
      def additional_repository_storage
      ENV['QA_ADDITIONAL_REPOSITORY_STORAGE']
      end
      ......
      ......@@ -22,7 +22,7 @@ def post(url, payload, args = {})
      verify_ssl: false
      }
      RestClient::Request.execute(default_args.merge(args))
      RestClient::Request.execute(default_args.merge(with_canary(args)))
      rescue StandardError => e
      return_response_or_raise(e)
      end
      ......@@ -44,13 +44,16 @@ def get(url, args = {})
      end
      end
      def patch(url, payload = nil)
      def patch(url, payload = nil, args = {})
      with_retry_on_too_many_requests do
      RestClient::Request.execute(
      default_args = {
      method: :patch,
      url: url,
      payload: payload,
      verify_ssl: false)
      verify_ssl: false
      }
      RestClient::Request.execute(default_args.merge(with_canary(args)))
      rescue StandardError => e
      return_response_or_raise(e)
      end
      ......@@ -65,7 +68,7 @@ def put(url, payload = nil, args = {})
      verify_ssl: false
      }
      RestClient::Request.execute(default_args.merge(args))
      RestClient::Request.execute(default_args.merge(with_canary(args)))
      rescue StandardError => e
      return_response_or_raise(e)
      end
      ......@@ -97,6 +100,10 @@ def masked_url(url)
      url.sub(/private_token=[^&]*/, "private_token=[****]")
      end
      def with_canary(args)
      args.deep_merge(QA::Runtime::Env.canary_value)
      end
      def with_retry_on_too_many_requests
      response = nil
      ......
      ......@@ -339,4 +339,29 @@
      end
      end
      end
      describe '.canary_value' do
      context 'with QA_COOKIES set' do
      using RSpec::Parameterized::TableSyntax
      where(:cookie_value, :result) do
      'gitlab_canary=true' | { gitlab_canary: "true" }
      'other_cookie=value\;gitlab_canary=true' | { gitlab_canary: "true" }
      'gitlab_canary=false' | { gitlab_canary: "false" }
      'gitlab_canary=false\;other_cookie=value' | { gitlab_canary: "false" }
      end
      with_them do
      before do
      stub_env('QA_COOKIES', cookie_value)
      end
      it { expect(described_class.canary_value).to eq result }
      end
      end
      context 'without QA_COOKIES set' do
      it { expect(described_class.canary_value).to be_empty }
      end
      end
      end
      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