diff options
author | Vinnie Okada <vokada@mrvinn.com> | 2015-03-24 20:03:22 -0600 |
---|---|---|
committer | Vinnie Okada <vokada@mrvinn.com> | 2015-03-24 20:03:22 -0600 |
commit | 057c8c344b6518cb50b81607e0f88734fc164a9e (patch) | |
tree | 996afee0c0f33bd6308f83b330a179dc29dfb48a /spec | |
parent | 637ca0b388382112850fd3052a961bb07db34d14 (diff) | |
parent | b9372c999707558b695fa401b4f660a3d38fce86 (diff) | |
download | gitlab-ce-057c8c344b6518cb50b81607e0f88734fc164a9e.tar.gz |
Merge branch 'master' into markdown-tags
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/users_controller_spec.rb | 21 | ||||
-rw-r--r-- | spec/helpers/gitlab_markdown_helper_spec.rb | 11 | ||||
-rw-r--r-- | spec/lib/gitlab/backend/grack_auth_spec.rb | 52 | ||||
-rw-r--r-- | spec/lib/gitlab/backend/rack_attack_helpers_spec.rb | 35 | ||||
-rw-r--r-- | spec/mailers/notify_spec.rb | 98 | ||||
-rw-r--r-- | spec/models/repository_spec.rb | 45 |
6 files changed, 204 insertions, 58 deletions
diff --git a/spec/controllers/users_controller_spec.rb b/spec/controllers/users_controller_spec.rb index 7962bcdde71..d47a37914df 100644 --- a/spec/controllers/users_controller_spec.rb +++ b/spec/controllers/users_controller_spec.rb @@ -25,34 +25,21 @@ describe UsersController do end describe 'GET #calendar_activities' do - include RepoHelpers - let(:project) { create(:project) } - let(:calendar_user) { create(:user, email: sample_commit.author_email) } - let(:commit1) { '0ed8c6c6752e8c6ea63e7b92a517bf5ac1209c80' } - let(:commit2) { '7d3b0f7cff5f37573aea97cebfd5692ea1689924' } + let!(:project) { create(:project) } + let!(:user) { create(:user) } before do allow_any_instance_of(User).to receive(:contributed_projects_ids).and_return([project.id]) project.team << [user, :developer] end - it 'assigns @commit_count' do - get :calendar_activities, username: calendar_user.username, date: '2014-07-31' - expect(assigns(:commit_count)).to eq(2) - end - it 'assigns @calendar_date' do - get :calendar_activities, username: calendar_user.username, date: '2014-07-31' + get :calendar_activities, username: user.username, date: '2014-07-31' expect(assigns(:calendar_date)).to eq(Date.parse('2014-07-31')) end - it 'assigns @calendar_activities' do - get :calendar_activities, username: calendar_user.username, date: '2014-07-31' - expect(assigns(:calendar_activities).values.flatten.map(&:id)).to eq([commit1, commit2]) - end - it 'renders calendar_activities' do - get :calendar_activities, username: calendar_user.username + get :calendar_activities, username: user.username expect(response).to render_template('calendar_activities') end end diff --git a/spec/helpers/gitlab_markdown_helper_spec.rb b/spec/helpers/gitlab_markdown_helper_spec.rb index 3a884d39bf1..c631acc591d 100644 --- a/spec/helpers/gitlab_markdown_helper_spec.rb +++ b/spec/helpers/gitlab_markdown_helper_spec.rb @@ -847,6 +847,17 @@ EOT ) end + it 'should render checkboxes for nested tasks' do + rendered_text = markdown(@source_text_asterisk, parse_tasks: true) + + expect(rendered_text).to match( + /<input.*checkbox.*valid unchecked nested task/ + ) + expect(rendered_text).to match( + /<input.*checkbox.*valid checked nested task/ + ) + end + it 'should not be confused by whitespace before bullets' do rendered_text_asterisk = markdown(@source_text_asterisk, parse_tasks: true) diff --git a/spec/lib/gitlab/backend/grack_auth_spec.rb b/spec/lib/gitlab/backend/grack_auth_spec.rb index 768312f0028..d0aad54f677 100644 --- a/spec/lib/gitlab/backend/grack_auth_spec.rb +++ b/spec/lib/gitlab/backend/grack_auth_spec.rb @@ -6,7 +6,7 @@ describe Grack::Auth do let(:app) { lambda { |env| [200, {}, "Success!"] } } let!(:auth) { Grack::Auth.new(app) } - let(:env) { + let(:env) { { "rack.input" => "", "REQUEST_METHOD" => "GET", @@ -85,6 +85,17 @@ describe Grack::Auth do it "responds with status 401" do expect(status).to eq(401) end + + context "when the user is IP banned" do + before do + expect(Rack::Attack::Allow2Ban).to receive(:filter).and_return(true) + allow_any_instance_of(Rack::Request).to receive(:ip).and_return('1.2.3.4') + end + + it "responds with status 401" do + expect(status).to eq(401) + end + end end context "when authentication succeeds" do @@ -109,10 +120,49 @@ describe Grack::Auth do end context "when the user isn't blocked" do + before do + expect(Rack::Attack::Allow2Ban).to receive(:reset) + end + it "responds with status 200" do expect(status).to eq(200) end end + + context "when blank password attempts follow a valid login" do + let(:options) { Gitlab.config.rack_attack.git_basic_auth } + let(:maxretry) { options[:maxretry] - 1 } + let(:ip) { '1.2.3.4' } + + before do + allow_any_instance_of(Rack::Request).to receive(:ip).and_return(ip) + Rack::Attack::Allow2Ban.reset(ip, options) + end + + after do + Rack::Attack::Allow2Ban.reset(ip, options) + end + + def attempt_login(include_password) + password = include_password ? user.password : "" + env["HTTP_AUTHORIZATION"] = ActionController::HttpAuthentication::Basic.encode_credentials(user.username, password) + Grack::Auth.new(app) + auth.call(env).first + end + + it "repeated attempts followed by successful attempt" do + for n in 0..maxretry do + expect(attempt_login(false)).to eq(401) + end + + expect(attempt_login(true)).to eq(200) + expect(Rack::Attack::Allow2Ban.send(:banned?, ip)).to eq(nil) + + for n in 0..maxretry do + expect(attempt_login(false)).to eq(401) + end + end + end end context "when the user doesn't have access to the project" do diff --git a/spec/lib/gitlab/backend/rack_attack_helpers_spec.rb b/spec/lib/gitlab/backend/rack_attack_helpers_spec.rb new file mode 100644 index 00000000000..2ac496fd669 --- /dev/null +++ b/spec/lib/gitlab/backend/rack_attack_helpers_spec.rb @@ -0,0 +1,35 @@ +require "spec_helper" + +describe 'RackAttackHelpers' do + describe 'reset' do + let(:discriminator) { 'test-key'} + let(:maxretry) { 5 } + let(:period) { 1.minute } + let(:options) { { findtime: period, bantime: 60, maxretry: maxretry } } + + def do_filter + for i in 1..maxretry - 1 do + status = Rack::Attack::Allow2Ban.filter(discriminator, options) { true } + expect(status).to eq(false) + end + end + + def do_reset + Rack::Attack::Allow2Ban.reset(discriminator, options) + end + + before do + do_reset + end + + after do + do_reset + end + + it 'user is not banned after n - 1 retries' do + do_filter + do_reset + do_filter + end + end +end diff --git a/spec/mailers/notify_spec.rb b/spec/mailers/notify_spec.rb index e3a3b542358..ba42f9e5c70 100644 --- a/spec/mailers/notify_spec.rb +++ b/spec/mailers/notify_spec.rb @@ -640,6 +640,100 @@ describe Notify do end end + describe 'email on push for a created branch' do + let(:example_site_path) { root_path } + let(:user) { create(:user) } + let(:tree_path) { namespace_project_tree_path(project.namespace, project, "master") } + + subject { Notify.repository_push_email(project.id, 'devs@company.name', author_id: user.id, ref: 'refs/heads/master', action: :create) } + + it 'is sent as the author' do + sender = subject.header[:from].addrs[0] + expect(sender.display_name).to eq(user.name) + expect(sender.address).to eq(gitlab_sender) + end + + it 'is sent to recipient' do + is_expected.to deliver_to 'devs@company.name' + end + + it 'has the correct subject' do + is_expected.to have_subject /Pushed new branch master/ + end + + it 'contains a link to the branch' do + is_expected.to have_body_text /#{tree_path}/ + end + end + + describe 'email on push for a created tag' do + let(:example_site_path) { root_path } + let(:user) { create(:user) } + let(:tree_path) { namespace_project_tree_path(project.namespace, project, "v1.0") } + + subject { Notify.repository_push_email(project.id, 'devs@company.name', author_id: user.id, ref: 'refs/tags/v1.0', action: :create) } + + it 'is sent as the author' do + sender = subject.header[:from].addrs[0] + expect(sender.display_name).to eq(user.name) + expect(sender.address).to eq(gitlab_sender) + end + + it 'is sent to recipient' do + is_expected.to deliver_to 'devs@company.name' + end + + it 'has the correct subject' do + is_expected.to have_subject /Pushed new tag v1\.0/ + end + + it 'contains a link to the tag' do + is_expected.to have_body_text /#{tree_path}/ + end + end + + describe 'email on push for a deleted branch' do + let(:example_site_path) { root_path } + let(:user) { create(:user) } + + subject { Notify.repository_push_email(project.id, 'devs@company.name', author_id: user.id, ref: 'refs/heads/master', action: :delete) } + + it 'is sent as the author' do + sender = subject.header[:from].addrs[0] + expect(sender.display_name).to eq(user.name) + expect(sender.address).to eq(gitlab_sender) + end + + it 'is sent to recipient' do + is_expected.to deliver_to 'devs@company.name' + end + + it 'has the correct subject' do + is_expected.to have_subject /Deleted branch master/ + end + end + + describe 'email on push for a deleted tag' do + let(:example_site_path) { root_path } + let(:user) { create(:user) } + + subject { Notify.repository_push_email(project.id, 'devs@company.name', author_id: user.id, ref: 'refs/tags/v1.0', action: :delete) } + + it 'is sent as the author' do + sender = subject.header[:from].addrs[0] + expect(sender.display_name).to eq(user.name) + expect(sender.address).to eq(gitlab_sender) + end + + it 'is sent to recipient' do + is_expected.to deliver_to 'devs@company.name' + end + + it 'has the correct subject' do + is_expected.to have_subject /Deleted tag v1\.0/ + end + end + describe 'email on push with multiple commits' do let(:example_site_path) { root_path } let(:user) { create(:user) } @@ -648,7 +742,7 @@ describe Notify do let(:diff_path) { namespace_project_compare_path(project.namespace, project, from: Commit.new(compare.base), to: Commit.new(compare.head)) } let(:send_from_committer_email) { false } - subject { Notify.repository_push_email(project.id, 'devs@company.name', user.id, 'master', compare, false, send_from_committer_email) } + subject { Notify.repository_push_email(project.id, 'devs@company.name', author_id: user.id, ref: 'refs/heads/master', action: :push, compare: compare, reverse_compare: false, send_from_committer_email: send_from_committer_email) } it 'is sent as the author' do sender = subject.header[:from].addrs[0] @@ -736,7 +830,7 @@ describe Notify do let(:commits) { Commit.decorate(compare.commits) } let(:diff_path) { namespace_project_commit_path(project.namespace, project, commits.first) } - subject { Notify.repository_push_email(project.id, 'devs@company.name', user.id, 'master', compare) } + subject { Notify.repository_push_email(project.id, 'devs@company.name', author_id: user.id, ref: 'refs/heads/master', action: :push, compare: compare) } it 'is sent as the author' do sender = subject.header[:from].addrs[0] diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 0e3e0b167d7..f41e5a97ca3 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -13,47 +13,16 @@ describe Repository do it { is_expected.not_to include('fix') } end - describe :last_commit_for_path do - subject { repository.last_commit_for_path(sample_commit.id, '.gitignore').id } - - it { is_expected.to eq('c1acaa58bbcbc3eafe538cb8274ba387047b69f8') } - end - - context :timestamps_by_user_log do - before do - Date.stub(:today).and_return(Date.new(2015, 03, 01)) - end - - describe 'single e-mail for user' do - let(:user) { create(:user, email: sample_commit.author_email) } - - subject { repository.timestamps_by_user_log(user) } + describe :tag_names_contains do + subject { repository.tag_names_contains(sample_commit.id) } - it { is_expected.to eq(['2014-08-06', '2014-07-31', '2014-07-31']) } - end - - describe 'multiple emails for user' do - let(:email_alias) { create(:email, email: another_sample_commit.author_email) } - let(:user) { create(:user, email: sample_commit.author_email, emails: [email_alias]) } - - subject { repository.timestamps_by_user_log(user) } - - it { is_expected.to eq(['2015-01-10', '2014-08-06', '2014-07-31', '2014-07-31']) } - end + it { is_expected.to include('v1.1.0') } + it { is_expected.not_to include('v1.0.0') } end - context :commits_by_user_on_date_log do - - describe 'single e-mail for user' do - let(:user) { create(:user, email: sample_commit.author_email) } - let(:commit1) { '0ed8c6c6752e8c6ea63e7b92a517bf5ac1209c80' } - let(:commit2) { '7d3b0f7cff5f37573aea97cebfd5692ea1689924' } - - subject { repository.commits_by_user_on_date_log(user,Date.new(2014, 07, 31)) } + describe :last_commit_for_path do + subject { repository.last_commit_for_path(sample_commit.id, '.gitignore').id } - it 'contains the exepected commits' do - expect(subject.flatten.map(&:id)).to eq([commit1, commit2]) - end - end + it { is_expected.to eq('c1acaa58bbcbc3eafe538cb8274ba387047b69f8') } end end |