<commit_before>require 'digest/sha1'

module QA
  feature 'cloning code using a deploy key', :core, :docker do
    def login
      Runtime::Browser.visit(:gitlab, Page::Main::Login)
      Page::Main::Login.act { sign_in_using_credentials }
    end

    before(:all) do
      login

      @runner_name = "qa-runner-#{Time.now.to_i}"

      @project = Factory::Resource::Project.fabricate! do |resource|
        resource.name = 'deploy-key-clone-project'
      end

      @repository_uri = @project.repository_ssh_uri

      Factory::Resource::Runner.fabricate! do |resource|
        resource.project = @project
        resource.name = @runner_name
        resource.tags = %w[qa docker]
        resource.image = 'gitlab/gitlab-runner:ubuntu'
      end
    end

    after(:all) do
      Service::Runner.new(@runner_name).remove!
    end

    keys = [
      Runtime::Key::RSA.new(8192),
      Runtime::Key::ECDSA.new(521),
      Runtime::Key::ED25519.new
    ]

    keys.each do |key|
      scenario "user sets up a deploy key with #{key.name}(#{key.bits}) to clone code using pipelines" do
        login

        Factory::Resource::DeployKey.fabricate! do |resource|
          resource.project = @project
          resource.title = "deploy key #{key.name}(#{key.bits})"
          resource.key = key.public_key
        end

        deploy_key_name = "DEPLOY_KEY_#{key.name}_#{key.bits}"

        Factory::Resource::SecretVariable.fabricate! do |resource|
          resource.project = @project
          resource.key = deploy_key_name
          resource.value = key.private_key
        end

        gitlab_ci = <<~YAML
          cat-config:
            script:
              - mkdir -p ~/.ssh
              - ssh-keyscan -p #{@repository_uri.port} #{@repository_uri.host} >> ~/.ssh/known_hosts
              - eval $(ssh-agent -s)
              - echo "$#{deploy_key_name}" | ssh-add -
              - git clone #{@repository_uri.git_uri}
              - sha1sum #{@project.name}/.gitlab-ci.yml
            tags:
              - qa
              - docker
        YAML
<commit_msg>Sign out so we could sign in; Clean up previous keys<commit_after>require 'digest/sha1'

module QA
  feature 'cloning code using a deploy key', :core, :docker do
    def login
      Runtime::Browser.visit(:gitlab, Page::Main::Login)
      Page::Main::Login.act { sign_in_using_credentials }
    end

    before(:all) do
      login

      @runner_name = "qa-runner-#{Time.now.to_i}"

      @project = Factory::Resource::Project.fabricate! do |resource|
        resource.name = 'deploy-key-clone-project'
      end

      @repository_uri = @project.repository_ssh_uri

      Factory::Resource::Runner.fabricate! do |resource|
        resource.project = @project
        resource.name = @runner_name
        resource.tags = %w[qa docker]
        resource.image = 'gitlab/gitlab-runner:ubuntu'
      end

      Page::Menu::Main.act { sign_out }
    end

    after(:all) do
      Service::Runner.new(@runner_name).remove!
    end

    keys = [
      Runtime::Key::RSA.new(8192),
      Runtime::Key::ECDSA.new(521),
      Runtime::Key::ED25519.new
    ]

    keys.each do |key|
      scenario "user sets up a deploy key with #{key.name}(#{key.bits}) to clone code using pipelines" do
        login

        Factory::Resource::DeployKey.fabricate! do |resource|
          resource.project = @project
          resource.title = "deploy key #{key.name}(#{key.bits})"
          resource.key = key.public_key
        end

        deploy_key_name = "DEPLOY_KEY_#{key.name}_#{key.bits}"

        Factory::Resource::SecretVariable.fabricate! do |resource|
          resource.project = @project
          resource.key = deploy_key_name
          resource.value = key.private_key
        end

        gitlab_ci = <<~YAML
          cat-config:
            script:
              - mkdir -p ~/.ssh
              - ssh-keyscan -p #{@repository_uri.port} #{@repository_uri.host} >> ~/.ssh/known_hosts
              - eval $(ssh-agent -s)
              - ssh-add -D
              - echo "$#{deploy_key_name}" | ssh-add -
              - git clone #{@repository_uri.git_uri}
              - sha1sum #{@project.name}/.gitlab-ci.yml
            tags:
              - qa
              - docker
        YAML

{'fraction_non_alphanumeric': 0.12567535823349776, 'fraction_numerical': 0.006577401926239136, 'mean_word_length': 2.0567121320890167, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '931466', 'n_tokens_mistral': 1362, 'n_tokens_neox': 1281, 'n_words': 268}