mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
FEATURE: Delegated authentication via user api keys (#7272)
This commit is contained in:
@ -345,6 +345,61 @@ RSpec.describe ApplicationController do
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Delegated auth' do
|
||||
let :public_key do
|
||||
<<~TXT
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDh7BS7Ey8hfbNhlNAW/47pqT7w
|
||||
IhBz3UyBYzin8JurEQ2pY9jWWlY8CH147KyIZf1fpcsi7ZNxGHeDhVsbtUKZxnFV
|
||||
p16Op3CHLJnnJKKBMNdXMy0yDfCAHZtqxeBOTcCo1Vt/bHpIgiK5kmaekyXIaD0n
|
||||
w0z/BYpOgZ8QwnI5ZwIDAQAB
|
||||
-----END PUBLIC KEY-----
|
||||
TXT
|
||||
end
|
||||
|
||||
let :args do
|
||||
{
|
||||
auth_redirect: 'http://no-good.com',
|
||||
user_api_public_key: "not-a-valid-public-key"
|
||||
}
|
||||
end
|
||||
|
||||
it 'disallows invalid public_key param' do
|
||||
args[:auth_redirect] = "discourse://auth_redirect"
|
||||
get "/latest", params: args
|
||||
|
||||
expect(response.body).to eq(I18n.t("user_api_key.invalid_public_key"))
|
||||
end
|
||||
|
||||
it 'does not allow invalid auth_redirect' do
|
||||
args[:user_api_public_key] = public_key
|
||||
get "/latest", params: args
|
||||
|
||||
expect(response.body).to eq(I18n.t("user_api_key.invalid_auth_redirect"))
|
||||
end
|
||||
|
||||
it 'does not redirect if one_time_password scope is disallowed' do
|
||||
SiteSetting.allow_user_api_key_scopes = "read|write"
|
||||
args[:user_api_public_key] = public_key
|
||||
args[:auth_redirect] = "discourse://auth_redirect"
|
||||
|
||||
get "/latest", params: args
|
||||
|
||||
expect(response.status).to_not eq(302)
|
||||
expect(response).to_not redirect_to("#{args[:auth_redirect]}?otp=true")
|
||||
end
|
||||
|
||||
it 'redirects correctly with valid params' do
|
||||
args[:user_api_public_key] = public_key
|
||||
args[:auth_redirect] = "discourse://auth_redirect"
|
||||
|
||||
get "/categories", params: args
|
||||
|
||||
expect(response.status).to eq(302)
|
||||
expect(response).to redirect_to("#{args[:auth_redirect]}?otp=true")
|
||||
end
|
||||
end
|
||||
|
||||
describe 'Content Security Policy' do
|
||||
it 'is enabled by SiteSettings' do
|
||||
SiteSetting.content_security_policy = false
|
||||
|
Reference in New Issue
Block a user