File: beyond_identity_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 (86 lines) | stat: -rw-r--r-- 2,557 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
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Integrations::BeyondIdentity, feature_category: :integrations do
  subject(:integration) { create(:beyond_identity_integration) }

  describe 'validations' do
    context 'when inactive' do
      before do
        integration.active = false
      end

      it { is_expected.not_to validate_presence_of(:token) }
    end

    context 'when active' do
      it { is_expected.to validate_presence_of(:token) }
    end
  end

  describe 'attributes' do
    it 'configures attributes' do
      expect(integration.supported_events).to be_blank
      expect(integration.to_param).to eq('beyond_identity')
      expect(integration.title).to eq('Beyond Identity')

      expect(integration.description).to eq(
        'Verify that GPG keys are authorized by Beyond Identity Authenticator.'
      )

      expect(integration.help).to include(
        'Verify that GPG keys are authorized by Beyond Identity Authenticator.'
      )
    end
  end

  describe '.api_arguments' do
    it 'returns api arguments' do
      expect(described_class.api_arguments).to eq([{
        required: true,
        name: :token,
        type: String,
        desc: 'API Token. User must have access to `git-commit-signing` endpoint.'
      }, {
        required: false,
        name: :exclude_service_accounts,
        type: Grape::API::Boolean,
        desc: "If enabled, Beyond Identity will not check commits from service accounts."
      }])
    end
  end

  describe '#execute' do
    it 'performs a request to beyond identity service' do
      params = { key_id: 'key-id', committer_email: 'email' }
      response = 'response'

      expect_next_instance_of(::Gitlab::BeyondIdentity::Client) do |instance|
        expect(instance).to receive(:execute).with(params).and_return(response)
      end

      expect(integration.execute(params)).to eq(response)
    end
  end

  describe '.activated_for_instance?' do
    let!(:integration) { create(:beyond_identity_integration, instance: instance, active: active, group: group) }
    let_it_be(:group_for_integration) { create(:group) }

    subject { described_class.activated_for_instance? }

    using RSpec::Parameterized::TableSyntax

    where(:instance, :group, :active, :expected) do
      true  | nil | true | true
      false | lazy { group_for_integration } | true | false
      true  | nil | false | false
      false | lazy { group_for_integration } | false | false
    end

    with_them do
      it { is_expected.to eq(expected) }
    end
  end
end