diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-21 03:08:37 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-21 03:08:37 +0000 |
commit | 2399724614f3c4dcf3059038d997193830de93ee (patch) | |
tree | 3315c4453ef3efb5c1162911753436cad4f3e57d /spec/support/shared_contexts | |
parent | 6755df108b123ecc8ae330d7c7bf2f04fbf36a81 (diff) | |
download | gitlab-ce-2399724614f3c4dcf3059038d997193830de93ee.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/support/shared_contexts')
19 files changed, 132 insertions, 22 deletions
diff --git a/spec/support/shared_contexts/change_access_checks_shared_context.rb b/spec/support/shared_contexts/change_access_checks_shared_context.rb index aca18b0c73b..e1ab81b4e3d 100644 --- a/spec/support/shared_contexts/change_access_checks_shared_context.rb +++ b/spec/support/shared_contexts/change_access_checks_shared_context.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -shared_context 'change access checks context' do +RSpec.shared_context 'change access checks context' do let(:user) { create(:user) } let(:project) { create(:project, :repository) } let(:user_access) { Gitlab::UserAccess.new(user, project: project) } diff --git a/spec/support/shared_contexts/controllers/githubish_import_controller_shared_context.rb b/spec/support/shared_contexts/controllers/githubish_import_controller_shared_context.rb new file mode 100644 index 00000000000..d4320e928a9 --- /dev/null +++ b/spec/support/shared_contexts/controllers/githubish_import_controller_shared_context.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +RSpec.shared_context 'a GitHub-ish import controller' do + let(:user) { create(:user) } + let(:token) { "asdasd12345" } + let(:access_params) { { github_access_token: token } } + + before do + sign_in(user) + allow(controller).to receive(:"#{provider}_import_enabled?").and_return(true) + end +end diff --git a/spec/support/shared_contexts/controllers/ldap_omniauth_callbacks_controller_shared_context.rb b/spec/support/shared_contexts/controllers/ldap_omniauth_callbacks_controller_shared_context.rb new file mode 100644 index 00000000000..4426d3af908 --- /dev/null +++ b/spec/support/shared_contexts/controllers/ldap_omniauth_callbacks_controller_shared_context.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +RSpec.shared_context 'Ldap::OmniauthCallbacksController' do + include LoginHelpers + include LdapHelpers + + let(:uid) { 'my-uid' } + let(:provider) { 'ldapmain' } + let(:valid_login?) { true } + let(:user) { create(:omniauth_user, extern_uid: uid, provider: provider) } + let(:ldap_setting_defaults) { { enabled: true, servers: ldap_server_config } } + let(:ldap_settings) { ldap_setting_defaults } + let(:ldap_server_config) do + { main: ldap_config_defaults(:main) } + end + + def ldap_config_defaults(key, hash = {}) + { + provider_name: "ldap#{key}", + attributes: {}, + encryption: 'plain' + }.merge(hash) + end + + before do + stub_ldap_setting(ldap_settings) + described_class.define_providers! + Rails.application.reload_routes! + + @original_env_config_omniauth_auth = mock_auth_hash(provider.to_s, uid, user.email) + stub_omniauth_provider(provider, context: request) + + allow(Gitlab::Auth::LDAP::Access).to receive(:allowed?).and_return(valid_login?) + end + + after do + Rails.application.env_config['omniauth.auth'] = @original_env_config_omniauth_auth + end + + after(:all) do + Rails.application.reload_routes! + end +end diff --git a/spec/support/shared_contexts/email_shared_context.rb b/spec/support/shared_contexts/email_shared_context.rb index b4d061a8215..b4d7722f03d 100644 --- a/spec/support/shared_contexts/email_shared_context.rb +++ b/spec/support/shared_contexts/email_shared_context.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -shared_context :email_shared_context do +RSpec.shared_context :email_shared_context do let(:mail_key) { "59d8df8370b7e95c5a49fbf86aeb2c93" } let(:receiver) { Gitlab::Email::Receiver.new(email_raw) } let(:markdown) { "![image](uploads/image.png)" } @@ -18,7 +18,7 @@ shared_context :email_shared_context do end end -shared_examples :reply_processing_shared_examples do +RSpec.shared_examples :reply_processing_shared_examples do context "when the user could not be found" do before do user.destroy diff --git a/spec/support/shared_contexts/finders/group_projects_finder_shared_contexts.rb b/spec/support/shared_contexts/finders/group_projects_finder_shared_contexts.rb index e7fee7239fc..58ee48a98f1 100644 --- a/spec/support/shared_contexts/finders/group_projects_finder_shared_contexts.rb +++ b/spec/support/shared_contexts/finders/group_projects_finder_shared_contexts.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require 'spec_helper' - RSpec.shared_context 'GroupProjectsFinder context' do let(:group) { create(:group) } let(:subgroup) { create(:group, parent: group) } diff --git a/spec/support/shared_contexts/finders/issues_finder_shared_contexts.rb b/spec/support/shared_contexts/finders/issues_finder_shared_contexts.rb index 6c96b18d834..6b950a354cf 100644 --- a/spec/support/shared_contexts/finders/issues_finder_shared_contexts.rb +++ b/spec/support/shared_contexts/finders/issues_finder_shared_contexts.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require 'spec_helper' - RSpec.shared_context 'IssuesFinder context' do set(:user) { create(:user) } set(:user2) { create(:user) } diff --git a/spec/support/shared_contexts/finders/merge_requests_finder_shared_contexts.rb b/spec/support/shared_contexts/finders/merge_requests_finder_shared_contexts.rb index ef1e65d2577..82190fb7793 100644 --- a/spec/support/shared_contexts/finders/merge_requests_finder_shared_contexts.rb +++ b/spec/support/shared_contexts/finders/merge_requests_finder_shared_contexts.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require 'spec_helper' - RSpec.shared_context 'MergeRequestsFinder multiple projects with merge requests context' do include ProjectForksHelper diff --git a/spec/support/shared_contexts/finders/users_finder_shared_contexts.rb b/spec/support/shared_contexts/finders/users_finder_shared_contexts.rb index d6404b2ee4b..a2fa3d7beac 100644 --- a/spec/support/shared_contexts/finders/users_finder_shared_contexts.rb +++ b/spec/support/shared_contexts/finders/users_finder_shared_contexts.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require 'spec_helper' - RSpec.shared_context 'UsersFinder#execute filter by project context' do set(:normal_user) { create(:user, username: 'johndoe') } set(:blocked_user) { create(:user, :blocked, username: 'notsorandom') } diff --git a/spec/support/shared_contexts/json_response_shared_context.rb b/spec/support/shared_contexts/json_response_shared_context.rb index bd37c97ed35..6a0734decd5 100644 --- a/spec/support/shared_contexts/json_response_shared_context.rb +++ b/spec/support/shared_contexts/json_response_shared_context.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -shared_context 'JSON response' do +RSpec.shared_context 'JSON response' do let(:json_response) { JSON.parse(response.body) } end diff --git a/spec/support/shared_contexts/mailers/notify_shared_context.rb b/spec/support/shared_contexts/mailers/notify_shared_context.rb new file mode 100644 index 00000000000..d5b44f8df2c --- /dev/null +++ b/spec/support/shared_contexts/mailers/notify_shared_context.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +RSpec.shared_context 'gitlab email notification' do + set(:group) { create(:group) } + set(:subgroup) { create(:group, parent: group) } + set(:project) { create(:project, :repository, name: 'a-known-name', group: group) } + set(:recipient) { create(:user, email: 'recipient@example.com') } + + let(:gitlab_sender_display_name) { Gitlab.config.gitlab.email_display_name } + let(:gitlab_sender) { Gitlab.config.gitlab.email_from } + let(:gitlab_sender_reply_to) { Gitlab.config.gitlab.email_reply_to } + let(:new_user_address) { 'newguy@example.com' } + + before do + email = recipient.emails.create(email: "notifications@example.com") + recipient.update_attribute(:notification_email, email.email) + stub_incoming_email_setting(enabled: true, address: "reply+%{key}@#{Gitlab.config.gitlab.host}") + end +end + +RSpec.shared_context 'reply-by-email is enabled with incoming address without %{key}' do + before do + stub_incoming_email_setting(enabled: true, address: "reply@#{Gitlab.config.gitlab.host}") + end +end diff --git a/spec/support/shared_contexts/merge_request_create.rb b/spec/support/shared_contexts/merge_request_create_shared_context.rb index 529f481c2b6..f2defa4eab9 100644 --- a/spec/support/shared_contexts/merge_request_create.rb +++ b/spec/support/shared_contexts/merge_request_create_shared_context.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -shared_context 'merge request create context' do +RSpec.shared_context 'merge request create context' do let(:user) { create(:user) } let(:user2) { create(:user) } let(:target_project) { create(:project, :public, :repository) } diff --git a/spec/support/shared_contexts/merge_request_edit.rb b/spec/support/shared_contexts/merge_request_edit_shared_context.rb index c84510ff47d..d490d26adfb 100644 --- a/spec/support/shared_contexts/merge_request_edit.rb +++ b/spec/support/shared_contexts/merge_request_edit_shared_context.rb @@ -1,7 +1,6 @@ # frozen_string_literal: true -require 'spec_helper' -shared_context 'merge request edit context' do +RSpec.shared_context 'merge request edit context' do let(:user) { create(:user) } let(:user2) { create(:user) } let!(:milestone) { create(:milestone, project: target_project) } diff --git a/spec/support/shared_contexts/merge_requests_allowing_collaboration.rb b/spec/support/shared_contexts/merge_requests_allowing_collaboration_shared_context.rb index 276ebf973c8..5412a991b22 100644 --- a/spec/support/shared_contexts/merge_requests_allowing_collaboration.rb +++ b/spec/support/shared_contexts/merge_requests_allowing_collaboration_shared_context.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -shared_context 'merge request allowing collaboration' do +RSpec.shared_context 'merge request allowing collaboration' do include ProjectForksHelper let(:canonical) { create(:project, :public, :repository) } diff --git a/spec/support/shared_contexts/rack_attack_shared_context.rb b/spec/support/shared_contexts/rack_attack_shared_context.rb index c925f565226..e7b2ee76c3c 100644 --- a/spec/support/shared_contexts/rack_attack_shared_context.rb +++ b/spec/support/shared_contexts/rack_attack_shared_context.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -shared_context 'rack attack cache store' do +RSpec.shared_context 'rack attack cache store' do around do |example| # Instead of test environment's :null_store so the throttles can increment Rack::Attack.cache.store = ActiveSupport::Cache::MemoryStore.new diff --git a/spec/support/shared_contexts/services_shared_context.rb b/spec/support/shared_contexts/services_shared_context.rb index 113bcc2af9c..c526c8aba7c 100644 --- a/spec/support/shared_contexts/services_shared_context.rb +++ b/spec/support/shared_contexts/services_shared_context.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true Service.available_services_names.each do |service| - shared_context service do + RSpec.shared_context service do let(:dashed_service) { service.dasherize } let(:service_method) { "#{service}_service".to_sym } let(:service_klass) { "#{service}_service".classify.constantize } diff --git a/spec/support/shared_contexts/session_shared_context.rb b/spec/support/shared_contexts/session_shared_context.rb index 86c145a8360..4cc87896f7e 100644 --- a/spec/support/shared_contexts/session_shared_context.rb +++ b/spec/support/shared_contexts/session_shared_context.rb @@ -4,7 +4,7 @@ # let(:session) variable # we do not use a parameter such as |session| because it does not play nice # with let variables -shared_context 'custom session' do +RSpec.shared_context 'custom session' do let!(:session) { {} } around do |example| diff --git a/spec/support/shared_contexts/unique_ip_check_shared_context.rb b/spec/support/shared_contexts/unique_ip_check_shared_context.rb new file mode 100644 index 00000000000..f6bedb6cada --- /dev/null +++ b/spec/support/shared_contexts/unique_ip_check_shared_context.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +RSpec.shared_context 'unique ips sign in limit' do + include StubENV + let(:request_context) { Gitlab::RequestContext.instance } + + before do + Gitlab::Redis::Cache.with(&:flushall) + Gitlab::Redis::Queues.with(&:flushall) + Gitlab::Redis::SharedState.with(&:flushall) + end + + before do + stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false') + + Gitlab::CurrentSettings.update!( + unique_ips_limit_enabled: true, + unique_ips_limit_time_window: 10000 + ) + + # Make sure we're working with the same reqeust context everywhere + allow(Gitlab::RequestContext).to receive(:instance).and_return(request_context) + end + + def change_ip(ip) + allow(request_context).to receive(:client_ip).and_return(ip) + end + + def request_from_ip(ip) + change_ip(ip) + request + response + end + + def operation_from_ip(ip) + change_ip(ip) + operation + end +end diff --git a/spec/support/shared_contexts/upload_type_check_shared_context.rb b/spec/support/shared_contexts/upload_type_check_shared_context.rb index 04c97500dd6..d29c498fd15 100644 --- a/spec/support/shared_contexts/upload_type_check_shared_context.rb +++ b/spec/support/shared_contexts/upload_type_check_shared_context.rb @@ -2,7 +2,7 @@ # Construct an `uploader` variable that is configured to `check_upload_type` # with `mime_types` and `extensions`. -shared_context 'uploader with type check' do +RSpec.shared_context 'uploader with type check' do let(:uploader_class) do Class.new(GitlabUploader) do include UploadTypeCheck::Concern @@ -20,7 +20,7 @@ shared_context 'uploader with type check' do end end -shared_context 'stubbed MimeMagic mime type detection' do +RSpec.shared_context 'stubbed MimeMagic mime type detection' do let(:mime_type) { '' } let(:magic_mime) { mime_type } let(:ext_mime) { mime_type } diff --git a/spec/support/shared_contexts/url_shared_context.rb b/spec/support/shared_contexts/url_shared_context.rb index 560cd500ecd..f3d227b6e2b 100644 --- a/spec/support/shared_contexts/url_shared_context.rb +++ b/spec/support/shared_contexts/url_shared_context.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -shared_context 'invalid urls' do +RSpec.shared_context 'invalid urls' do let(:urls_with_CRLF) do ["http://127.0.0.1:333/pa\rth", "http://127.0.0.1:333/pa\nth", |