You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
116 lines
2.5 KiB
116 lines
2.5 KiB
2 years ago
|
# frozen_string_literal: true
|
||
|
|
||
8 years ago
|
require 'rails_helper'
|
||
|
|
||
1 year ago
|
RSpec.describe 'Apps' do
|
||
|
describe 'POST /api/v1/apps' do
|
||
|
subject do
|
||
|
post '/api/v1/apps', params: params
|
||
|
end
|
||
8 years ago
|
|
||
1 year ago
|
let(:client_name) { 'Test app' }
|
||
|
let(:scopes) { nil }
|
||
4 years ago
|
let(:redirect_uris) { 'urn:ietf:wg:oauth:2.0:oob' }
|
||
1 year ago
|
let(:website) { nil }
|
||
4 years ago
|
|
||
1 year ago
|
let(:params) do
|
||
4 years ago
|
{
|
||
|
client_name: client_name,
|
||
|
redirect_uris: redirect_uris,
|
||
|
scopes: scopes,
|
||
|
website: website,
|
||
|
}
|
||
|
end
|
||
|
|
||
|
context 'with valid params' do
|
||
|
it 'returns http success' do
|
||
1 year ago
|
subject
|
||
|
|
||
4 years ago
|
expect(response).to have_http_status(200)
|
||
|
end
|
||
|
|
||
|
it 'creates an OAuth app' do
|
||
1 year ago
|
subject
|
||
|
|
||
|
expect(Doorkeeper::Application.find_by(name: client_name)).to be_present
|
||
4 years ago
|
end
|
||
|
|
||
|
it 'returns client ID and client secret' do
|
||
1 year ago
|
subject
|
||
4 years ago
|
|
||
1 year ago
|
body = body_as_json
|
||
|
|
||
|
expect(body[:client_id]).to be_present
|
||
|
expect(body[:client_secret]).to be_present
|
||
4 years ago
|
end
|
||
|
end
|
||
|
|
||
|
context 'with an unsupported scope' do
|
||
|
let(:scopes) { 'hoge' }
|
||
|
|
||
|
it 'returns http unprocessable entity' do
|
||
1 year ago
|
subject
|
||
|
|
||
4 years ago
|
expect(response).to have_http_status(422)
|
||
|
end
|
||
8 years ago
|
end
|
||
|
|
||
4 years ago
|
context 'with many duplicate scopes' do
|
||
|
let(:scopes) { (%w(read) * 40).join(' ') }
|
||
|
|
||
|
it 'returns http success' do
|
||
1 year ago
|
subject
|
||
|
|
||
4 years ago
|
expect(response).to have_http_status(200)
|
||
|
end
|
||
|
|
||
|
it 'only saves the scope once' do
|
||
1 year ago
|
subject
|
||
|
|
||
4 years ago
|
expect(Doorkeeper::Application.find_by(name: client_name).scopes.to_s).to eq 'read'
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context 'with a too-long name' do
|
||
|
let(:client_name) { 'hoge' * 20 }
|
||
|
|
||
|
it 'returns http unprocessable entity' do
|
||
1 year ago
|
subject
|
||
|
|
||
4 years ago
|
expect(response).to have_http_status(422)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context 'with a too-long website' do
|
||
2 years ago
|
let(:website) { "https://foo.bar/#{'hoge' * 2_000}" }
|
||
4 years ago
|
|
||
|
it 'returns http unprocessable entity' do
|
||
1 year ago
|
subject
|
||
|
|
||
4 years ago
|
expect(response).to have_http_status(422)
|
||
|
end
|
||
8 years ago
|
end
|
||
|
|
||
4 years ago
|
context 'with a too-long redirect_uris' do
|
||
2 years ago
|
let(:redirect_uris) { "https://foo.bar/#{'hoge' * 2_000}" }
|
||
8 years ago
|
|
||
4 years ago
|
it 'returns http unprocessable entity' do
|
||
1 year ago
|
subject
|
||
|
|
||
|
expect(response).to have_http_status(422)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
context 'without required params' do
|
||
|
let(:client_name) { '' }
|
||
|
let(:redirect_uris) { '' }
|
||
|
|
||
|
it 'returns http unprocessable entity' do
|
||
|
subject
|
||
|
|
||
4 years ago
|
expect(response).to have_http_status(422)
|
||
|
end
|
||
8 years ago
|
end
|
||
|
end
|
||
|
end
|