Skip to content

Commit

Permalink
OAuth2プロバイダーテストの追加と修正
Browse files Browse the repository at this point in the history
  • Loading branch information
MikotoMakizuru committed Feb 8, 2025
1 parent 7d5c60d commit 487c0b8
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions test/system/oauth2_provider_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
class Oauth2ProviderTest < ApplicationSystemTestCase
setup do
visit_with_auth root_path, 'komagata'
Doorkeeper::Application.create!(
name: 'Sample Application',
redirect_uri: 'https://example.com/callback',
scopes: 'read'
)
end

test 'admin can access oauth2 provider page' do
Expand All @@ -18,42 +23,54 @@ class Oauth2ProviderTest < ApplicationSystemTestCase
assert_text '管理者としてログインしてください'
end

test 'admin cat add a new application' do
test 'add an application' do
visit new_oauth_application_path
within('form[class="new_doorkeeper_application"]') do
fill_in 'Name', with: 'Sample Application'
fill_in 'Redirect uri', with: 'https://example.com/callback'
fill_in 'Redirect URL', with: 'https://example.com/callback'
fill_in 'Scopes', with: 'read'
end
click_on '登録する'
assert_text 'アプリケーションを追加しました。'
end

test 'admin can edit an application' do
test 'edit an application' do
visit "/oauth/applications/#{Doorkeeper::Application.last.id}/edit"
within('form[class="edit_doorkeeper_application"]') do
fill_in 'Name', with: 'Sample Application edited'
fill_in 'Redirect uri', with: 'https://example.com/callback/edited'
fill_in 'Redirect URL', with: 'https://example.com/callback/edited'
end
click_on '登録する'
assert_text 'アプリケーションを更新しました。'
end

test 'admin can delete an application' do
test 'delete an application' do
visit "/oauth/applications/#{Doorkeeper::Application.last.id}"
click_on '削除'
page.driver.browser.switch_to.alert.accept
assert_text 'アプリケーションを削除しました。'
end

test 'validate redirect uri' do
test 'validate when redirect url is not specified' do
visit new_oauth_application_path
within('form[class="new_doorkeeper_application"]') do
fill_in 'Name', with: 'Sample Application'
fill_in 'Redirect uri', with: 'invalid_uri'
fill_in 'Scopes', with: 'read'
end
click_on '登録する'
assert_text 'Redirect uriは不正な値です'
assert_text 'フォームにエラーが無いか確認してください'
assert_text 'を入力してください'
end

test 'validate redirect url with invalid value' do
visit new_oauth_application_path
within('form[class="new_doorkeeper_application"]') do
fill_in 'Name', with: 'Sample Application'
fill_in 'Redirect URL', with: 'invalid_uri'
fill_in 'Scopes', with: 'read'
end
click_on '登録する'
assert_text 'フォームにエラーが無いか確認してください'
assert_text 'Redirect urlの値が無効です'
end
end

0 comments on commit 487c0b8

Please sign in to comment.