Skip to content
代码片段 群组 项目
未验证 提交 1e95ad33 编辑于 作者: Jerry Seto's avatar Jerry Seto 提交者: GitLab
浏览文件

Merge branch 'fix_go_spec_tests' into 'master'

Fix skipped tests for Go middleware

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/170828



Merged-by: default avatarJerry Seto <jseto@gitlab.com>
Approved-by: default avatarOlaoluwa Oluro <olaoluro@gitlab.com>
Approved-by: default avatarJerry Seto <jseto@gitlab.com>
Co-authored-by: default avatarVasilii Iakliushin <viakliushin@gitlab.com>
No related branches found
No related tags found
无相关合并请求
......@@ -118,12 +118,6 @@
project.update_attribute(:visibility_level, Project::PRIVATE)
end
shared_examples 'when no authentication header' do
it 'returns the 2-segment group path' do
expect_response_with_path(go, enabled_protocol, group.full_path)
end
end
context 'when invalid authentication header exists' do
before do
env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials('invalid', 'invalid')
......@@ -166,56 +160,60 @@
expect_404_response(go)
end
end
end
context 'using basic auth' do
context 'using a personal access token' do
let(:personal_access_token) { create(:personal_access_token, user: current_user) }
context 'using basic auth' do
let(:current_user) { project.creator }
before do
env['REMOTE_ADDR'] = "192.168.0.1"
env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(current_user.username, personal_access_token.token)
end
context 'using a personal access token' do
let(:personal_access_token) { create(:personal_access_token, user: current_user) }
context 'with api scope' do
it_behaves_like 'when authenticated'
end
before do
env['REMOTE_ADDR'] = "192.168.0.1"
env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(current_user.username, personal_access_token.token)
end
context 'with read_user scope' do
before do
personal_access_token.update_attribute(:scopes, [:read_user])
end
context 'with api scope' do
it_behaves_like 'when authenticated'
end
it_behaves_like 'when invalid authentication header exists'
context 'with read_user scope' do
before do
personal_access_token.update_attribute(:scopes, [:read_user])
end
context 'with a denylisted ip' do
it 'returns forbidden' do
err = Gitlab::Auth::IpBlocked.new
expect(Gitlab::Auth).to receive(:find_for_git_client).and_raise(err)
response = go
expect(response[0]).to eq(403)
expect(response[2]).to eq([err.message])
end
it 'returns 404' do
expect_404_response(go)
end
end
context 'when a personal access token is missing' do
before do
env['REMOTE_ADDR'] = '192.168.0.1'
env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(current_user.username, 'dummy_password')
end
it 'returns unauthorized' do
expect(Gitlab::Auth).to receive(:find_for_git_client).and_raise(Gitlab::Auth::MissingPersonalAccessTokenError)
context 'with a denylisted ip' do
it 'returns forbidden' do
err = Gitlab::Auth::IpBlocked.new
expect(Gitlab::Auth).to receive(:find_for_git_client).and_raise(err)
response = go
expect(response[0]).to eq(401)
expect(response[1]['Content-Length']).to be_nil
expect(response[2]).to eq([''])
expect(response[0]).to eq(403)
expect(response[2]).to eq([err.message])
end
end
end
context 'when a personal access token is missing' do
before do
env['REMOTE_ADDR'] = '192.168.0.1'
env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(current_user.username, 'dummy_password')
end
it 'returns unauthorized' do
expect(Gitlab::Auth).to receive(:find_for_git_client).and_raise(Gitlab::Auth::MissingPersonalAccessTokenError)
response = go
expect(response[0]).to eq(401)
expect(response[1]['Content-Length']).to be_nil
expect(response[2]).to eq([''])
end
end
end
end
end
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册