|
|
|
@ -157,7 +157,7 @@ describe ::OAuthClients::ConnectionManager, type: :model do |
|
|
|
|
refresh_token: "UwFp...1FROJ", |
|
|
|
|
user_id: "admin" |
|
|
|
|
}.to_json |
|
|
|
|
stub_request(:any, File.join(host, '/apps/oauth2/api/v1/token')) |
|
|
|
|
stub_request(:any, File.join(host, '/index.php/apps/oauth2/api/v1/token')) |
|
|
|
|
.to_return(status: 200, body: response_body) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
@ -169,7 +169,7 @@ describe ::OAuthClients::ConnectionManager, type: :model do |
|
|
|
|
|
|
|
|
|
context 'with known error', webmock: true do |
|
|
|
|
before do |
|
|
|
|
stub_request(:post, File.join(host, '/apps/oauth2/api/v1/token')) |
|
|
|
|
stub_request(:post, File.join(host, '/index.php/apps/oauth2/api/v1/token')) |
|
|
|
|
.to_return(status: 400, body: { error: error_message }.to_json) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
@ -197,7 +197,7 @@ describe ::OAuthClients::ConnectionManager, type: :model do |
|
|
|
|
|
|
|
|
|
context 'with known reply invalid_grant', webmock: true do |
|
|
|
|
before do |
|
|
|
|
stub_request(:post, File.join(host, '/apps/oauth2/api/v1/token')) |
|
|
|
|
stub_request(:post, File.join(host, '/index.php/apps/oauth2/api/v1/token')) |
|
|
|
|
.to_return(status: 400, body: { error: "invalid_grant" }.to_json) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
@ -211,7 +211,7 @@ describe ::OAuthClients::ConnectionManager, type: :model do |
|
|
|
|
|
|
|
|
|
context 'with unknown reply', webmock: true do |
|
|
|
|
before do |
|
|
|
|
stub_request(:post, File.join(host, '/apps/oauth2/api/v1/token')) |
|
|
|
|
stub_request(:post, File.join(host, '/index.php/apps/oauth2/api/v1/token')) |
|
|
|
|
.to_return(status: 400, body: { error: "invalid_requesttt" }.to_json) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
@ -225,7 +225,7 @@ describe ::OAuthClients::ConnectionManager, type: :model do |
|
|
|
|
|
|
|
|
|
context 'with reply including JSON syntax error', webmock: true do |
|
|
|
|
before do |
|
|
|
|
stub_request(:post, File.join(host, '/apps/oauth2/api/v1/token')) |
|
|
|
|
stub_request(:post, File.join(host, '/index.php/apps/oauth2/api/v1/token')) |
|
|
|
|
.to_return( |
|
|
|
|
status: 400, |
|
|
|
|
headers: { 'Content-Type' => 'application/json; charset=utf-8' }, |
|
|
|
@ -243,7 +243,7 @@ describe ::OAuthClients::ConnectionManager, type: :model do |
|
|
|
|
|
|
|
|
|
context 'with 500 reply without body', webmock: true do |
|
|
|
|
before do |
|
|
|
|
stub_request(:post, File.join(host, '/apps/oauth2/api/v1/token')) |
|
|
|
|
stub_request(:post, File.join(host, '/index.php/apps/oauth2/api/v1/token')) |
|
|
|
|
.to_return(status: 500) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
@ -257,7 +257,7 @@ describe ::OAuthClients::ConnectionManager, type: :model do |
|
|
|
|
|
|
|
|
|
context 'with bad HTTP response', webmock: true do |
|
|
|
|
before do |
|
|
|
|
stub_request(:post, File.join(host, '/apps/oauth2/api/v1/token')).to_raise(Net::HTTPBadResponse) |
|
|
|
|
stub_request(:post, File.join(host, '/index.php/apps/oauth2/api/v1/token')).to_raise(Net::HTTPBadResponse) |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'returns an unspecific error message' do |
|
|
|
@ -270,7 +270,7 @@ describe ::OAuthClients::ConnectionManager, type: :model do |
|
|
|
|
|
|
|
|
|
context 'with timeout returns internal error', webmock: true do |
|
|
|
|
before do |
|
|
|
|
stub_request(:post, File.join(host, '/apps/oauth2/api/v1/token')).to_timeout |
|
|
|
|
stub_request(:post, File.join(host, '/index.php/apps/oauth2/api/v1/token')).to_timeout |
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
it 'returns an unspecific error message' do |
|
|
|
@ -303,7 +303,7 @@ describe ::OAuthClients::ConnectionManager, type: :model do |
|
|
|
|
refresh_token: "xUwFp...1FROJ", |
|
|
|
|
user_id: "admin" |
|
|
|
|
}.to_json |
|
|
|
|
stub_request(:any, File.join(host, '/apps/oauth2/api/v1/token')) |
|
|
|
|
stub_request(:any, File.join(host, '/index.php/apps/oauth2/api/v1/token')) |
|
|
|
|
.to_return(status: 200, body: response_body) |
|
|
|
|
oauth_client_token |
|
|
|
|
end |
|
|
|
@ -327,7 +327,7 @@ describe ::OAuthClients::ConnectionManager, type: :model do |
|
|
|
|
refresh_token: "xUwFp...1FROJ", |
|
|
|
|
user_id: "admin" |
|
|
|
|
}.to_json |
|
|
|
|
stub_request(:any, File.join(host, '/apps/oauth2/api/v1/token')) |
|
|
|
|
stub_request(:any, File.join(host, '/index.php/apps/oauth2/api/v1/token')) |
|
|
|
|
.to_return(status: 200, body: response_body) |
|
|
|
|
|
|
|
|
|
oauth_client_token |
|
|
|
@ -343,7 +343,7 @@ describe ::OAuthClients::ConnectionManager, type: :model do |
|
|
|
|
|
|
|
|
|
context 'with server error from OAuth2 provider' do |
|
|
|
|
before do |
|
|
|
|
stub_request(:any, File.join(host, '/apps/oauth2/api/v1/token')) |
|
|
|
|
stub_request(:any, File.join(host, '/index.php/apps/oauth2/api/v1/token')) |
|
|
|
|
.to_return(status: 400, body: { error: "invalid_request" }.to_json) |
|
|
|
|
oauth_client_token |
|
|
|
|
end |
|
|
|
@ -358,7 +358,7 @@ describe ::OAuthClients::ConnectionManager, type: :model do |
|
|
|
|
context 'with successful response but invalid data' do |
|
|
|
|
before do |
|
|
|
|
# Simulate timeout |
|
|
|
|
stub_request(:any, File.join(host, '/apps/oauth2/api/v1/token')) |
|
|
|
|
stub_request(:any, File.join(host, '/index.php/apps/oauth2/api/v1/token')) |
|
|
|
|
.to_timeout |
|
|
|
|
oauth_client_token |
|
|
|
|
end |
|
|
|
|