diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2024-01-12 03:08:51 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2024-01-12 03:08:51 +0300 |
commit | 98a00b024553a603e16380b93fc3f89a169bf438 (patch) | |
tree | 4a6dade546a6857bffc21df2126b113528d746d9 /spec/lib | |
parent | c53e365d68ee800702befb15adfdfac708d5de6f (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/slash_commands/presenters/access_spec.rb | 15 | ||||
-rw-r--r-- | spec/lib/gitlab/slash_commands/verify_request_spec.rb | 36 |
2 files changed, 51 insertions, 0 deletions
diff --git a/spec/lib/gitlab/slash_commands/presenters/access_spec.rb b/spec/lib/gitlab/slash_commands/presenters/access_spec.rb index 3af0ae03256..d83871d67a2 100644 --- a/spec/lib/gitlab/slash_commands/presenters/access_spec.rb +++ b/spec/lib/gitlab/slash_commands/presenters/access_spec.rb @@ -76,4 +76,19 @@ RSpec.describe Gitlab::SlashCommands::Presenters::Access do end end end + + describe '#confirm' do + let(:url) { 'https://example.com/api' } + + subject { described_class.new.confirm(url) } + + it { is_expected.to be_a(Hash) } + + it 'tells the user to confirm the request' do + expect(subject[:response_type]).to be(:ephemeral) + expect(subject[:text]).to match( + "Please confirm the request by accessing <#{url}|this link> through a web browser" + ) + end + end end diff --git a/spec/lib/gitlab/slash_commands/verify_request_spec.rb b/spec/lib/gitlab/slash_commands/verify_request_spec.rb new file mode 100644 index 00000000000..df6052ded93 --- /dev/null +++ b/spec/lib/gitlab/slash_commands/verify_request_spec.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::SlashCommands::VerifyRequest, feature_category: :integrations do + let_it_be(:integration) { create(:slack_slash_commands_integration) } + let_it_be(:chat_name) { create(:chat_name) } + let(:response_url) { 'http://www.example.com/' } + + subject(:verification) { described_class.new(integration, chat_name, response_url) } + + describe '#approve!' do + before do + stub_request(:post, "http://www.example.com/").to_return(status: 200, body: 'ok') + end + + it 'updates the token' do + expect { verification.approve! }.to change { chat_name.reload.token }.to(integration.token) + end + + it 'updates the ephemeral message' do + expect(Gitlab::HTTP).to receive(:post).with( + response_url, a_hash_including(body: an_instance_of(String), headers: an_instance_of(Hash)) + ).once + + verification.approve! + end + end + + describe '#valid?' do + it 'compares tokens' do + expect(ActiveSupport::SecurityUtils).to receive(:secure_compare).with(integration.token, chat_name.token) + verification.valid? + end + end +end |