File: ssh_keys_helper_spec.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (25 lines) | stat: -rw-r--r-- 939 bytes parent folder | download
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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe SshKeysHelper do
  describe '#ssh_key_allowed_algorithms' do
    it 'returns string with the names of allowed algorithms that are quoted and joined by commas' do
      allowed_algorithms = Gitlab::CurrentSettings.allowed_key_types.flat_map do |ssh_key_type_name|
        Gitlab::SSHPublicKey.supported_algorithms_for_name(ssh_key_type_name)
      end

      quoted_allowed_algorithms = allowed_algorithms.map { |name| "'#{name}'" }

      expected_string = Gitlab::Sentence.to_exclusive_sentence(quoted_allowed_algorithms)

      expect(ssh_key_allowed_algorithms).to eq(expected_string)
    end

    it 'returns only allowed algorithms' do
      expect(ssh_key_allowed_algorithms).to match('rsa')
      stub_application_setting(rsa_key_restriction: ApplicationSetting::FORBIDDEN_KEY_VALUE)
      expect(ssh_key_allowed_algorithms).not_to match('rsa')
    end
  end
end