2023-02-22 01:55:31 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-26 23:55:21 +02:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2023-06-14 09:48:48 +02:00
|
|
|
RSpec.describe 'Apps' do
|
|
|
|
describe 'POST /api/v1/apps' do
|
|
|
|
subject do
|
|
|
|
post '/api/v1/apps', params: params
|
|
|
|
end
|
2016-09-26 23:55:21 +02:00
|
|
|
|
2023-06-14 09:48:48 +02:00
|
|
|
let(:client_name) { 'Test app' }
|
|
|
|
let(:scopes) { nil }
|
2021-04-15 16:28:43 +02:00
|
|
|
let(:redirect_uris) { 'urn:ietf:wg:oauth:2.0:oob' }
|
2023-06-14 09:48:48 +02:00
|
|
|
let(:website) { nil }
|
2021-04-15 16:28:43 +02:00
|
|
|
|
2023-06-14 09:48:48 +02:00
|
|
|
let(:params) do
|
2021-04-15 16:28:43 +02:00
|
|
|
{
|
|
|
|
client_name: client_name,
|
|
|
|
redirect_uris: redirect_uris,
|
|
|
|
scopes: scopes,
|
|
|
|
website: website,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with valid params' do
|
2023-10-13 14:42:09 +02:00
|
|
|
it 'creates an OAuth app', :aggregate_failures do
|
2023-06-14 09:48:48 +02:00
|
|
|
subject
|
|
|
|
|
2021-04-15 16:28:43 +02:00
|
|
|
expect(response).to have_http_status(200)
|
2023-06-14 09:48:48 +02:00
|
|
|
expect(Doorkeeper::Application.find_by(name: client_name)).to be_present
|
2021-04-15 16:28:43 +02:00
|
|
|
|
2023-06-14 09:48:48 +02:00
|
|
|
body = body_as_json
|
|
|
|
|
|
|
|
expect(body[:client_id]).to be_present
|
|
|
|
expect(body[:client_secret]).to be_present
|
2021-04-15 16:28:43 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with an unsupported scope' do
|
|
|
|
let(:scopes) { 'hoge' }
|
|
|
|
|
|
|
|
it 'returns http unprocessable entity' do
|
2023-06-14 09:48:48 +02:00
|
|
|
subject
|
|
|
|
|
2021-04-15 16:28:43 +02:00
|
|
|
expect(response).to have_http_status(422)
|
|
|
|
end
|
2016-09-26 23:55:21 +02:00
|
|
|
end
|
|
|
|
|
2021-04-15 16:28:43 +02:00
|
|
|
context 'with many duplicate scopes' do
|
|
|
|
let(:scopes) { (%w(read) * 40).join(' ') }
|
|
|
|
|
2023-10-13 14:42:09 +02:00
|
|
|
it 'only saves the scope once', :aggregate_failures do
|
2023-06-14 09:48:48 +02:00
|
|
|
subject
|
|
|
|
|
2021-04-15 16:28:43 +02:00
|
|
|
expect(response).to have_http_status(200)
|
|
|
|
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
|
2023-06-14 09:48:48 +02:00
|
|
|
subject
|
|
|
|
|
2021-04-15 16:28:43 +02:00
|
|
|
expect(response).to have_http_status(422)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a too-long website' do
|
2023-02-22 01:54:36 +01:00
|
|
|
let(:website) { "https://foo.bar/#{'hoge' * 2_000}" }
|
2021-04-15 16:28:43 +02:00
|
|
|
|
|
|
|
it 'returns http unprocessable entity' do
|
2023-06-14 09:48:48 +02:00
|
|
|
subject
|
|
|
|
|
2021-04-15 16:28:43 +02:00
|
|
|
expect(response).to have_http_status(422)
|
|
|
|
end
|
2016-09-26 23:55:21 +02:00
|
|
|
end
|
|
|
|
|
2021-04-15 16:28:43 +02:00
|
|
|
context 'with a too-long redirect_uris' do
|
2023-02-22 01:54:36 +01:00
|
|
|
let(:redirect_uris) { "https://foo.bar/#{'hoge' * 2_000}" }
|
2016-09-26 23:55:21 +02:00
|
|
|
|
2021-04-15 16:28:43 +02:00
|
|
|
it 'returns http unprocessable entity' do
|
2023-06-14 09:48:48 +02:00
|
|
|
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
|
|
|
|
|
2021-04-15 16:28:43 +02:00
|
|
|
expect(response).to have_http_status(422)
|
|
|
|
end
|
2016-09-26 23:55:21 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|