From 487c0b82b3e0010fa69c45f855ceda6fe28c1c25 Mon Sep 17 00:00:00 2001 From: MikotoMakizuru Date: Sun, 26 Jan 2025 16:05:15 +0900 Subject: [PATCH] =?UTF-8?q?OAuth2=E3=83=97=E3=83=AD=E3=83=90=E3=82=A4?= =?UTF-8?q?=E3=83=80=E3=83=BC=E3=83=86=E3=82=B9=E3=83=88=E3=81=AE=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0=E3=81=A8=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/system/oauth2_provider_test.rb | 33 ++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/test/system/oauth2_provider_test.rb b/test/system/oauth2_provider_test.rb index c619ca5baa1..0f09083cc77 100644 --- a/test/system/oauth2_provider_test.rb +++ b/test/system/oauth2_provider_test.rb @@ -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 @@ -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