From 775602c9c024a7efb4691fe44086826c0fbf94d1 Mon Sep 17 00:00:00 2001 From: akadusei Date: Wed, 23 Oct 2024 13:09:01 +0000 Subject: [PATCH] Add support for Lucky v1.3 --- CHANGELOG.md | 7 ++ shard.latest.yml | 6 +- .../api/oauth/authorization/pipes_spec.cr | 75 ++++++++----------- spec/shield/actions/login_pipes_spec.cr | 12 +-- spec/shield/actions/oauth/pipes_spec.cr | 26 +++---- src/shield/actions/oauth/authorization/new.cr | 10 +-- src/shield/actions/oauth/authorize.cr | 14 ++-- 7 files changed, 73 insertions(+), 77 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89e34c7d..eb8d56ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [Unreleased] - + +### Fixed +- Add support for Lucky v1.3 +- Add support for Crystal v1.13 +- Add support for Crystal v1.14 + ## [1.3.1] - 2024-09-11 ### Removed diff --git a/shard.latest.yml b/shard.latest.yml index 78c8db8b..46439a6f 100644 --- a/shard.latest.yml +++ b/shard.latest.yml @@ -1,13 +1,13 @@ dependencies: avram: github: luckyframework/avram - version: ~> 1.2 + version: ~> 1.3 carbon: github: luckyframework/carbon - version: ~> 0.5.0 + version: ~> 0.6.0 lucky: github: luckyframework/lucky - version: ~> 1.2 + version: ~> 1.3 lucky_env: github: luckyframework/lucky_env version: ~> 0.2.0 diff --git a/spec/shield/actions/api/oauth/authorization/pipes_spec.cr b/spec/shield/actions/api/oauth/authorization/pipes_spec.cr index 8ed31a44..465beef7 100644 --- a/spec/shield/actions/api/oauth/authorization/pipes_spec.cr +++ b/spec/shield/actions/api/oauth/authorization/pipes_spec.cr @@ -13,13 +13,13 @@ class Spec::Api::Oauth::Authorization::Pipes < ApiAction before :oauth_require_code_challenge before :oauth_validate_code_challenge_method - param client_id : String? - param code_challenge : String? + param client_id : String? = nil + param code_challenge : String? = nil param code_challenge_method : String = "plain" - param redirect_uri : String? - param response_type : String? - param scope : String? - param state : String? + param redirect_uri : String? = nil + param response_type : String? = nil + param scope : String? = nil + param state : String? = nil get "/spec/api/oauth/authorization/pipes" do json({success: true}) @@ -33,15 +33,14 @@ end describe Shield::Api::Oauth::Authorization::Pipes do describe "#oauth_validate_client_id" do it "validates client ID" do - response = ApiClient.exec( - Spec::Api::Oauth::Authorization::Pipes, - client_id: 23, + response = ApiClient.exec(Spec::Api::Oauth::Authorization::Pipes.with( + client_id: "23", code_challenge: "a1b2c3", redirect_uri: "myapp://callback", response_type: "code", scope: "api.current_user.show", state: "abc123" - ) + )) response.should send_json( 400, @@ -56,14 +55,13 @@ describe Shield::Api::Oauth::Authorization::Pipes do developer = UserFactory.create oauth_client = OauthClientFactory.create &.user_id(developer.id) - response = ApiClient.exec( - Spec::Api::Oauth::Authorization::Pipes, - client_id: oauth_client.id, + response = ApiClient.exec(Spec::Api::Oauth::Authorization::Pipes.with( + client_id: oauth_client.id.hexstring, code_challenge: "a1b2c3", redirect_uri: oauth_client.redirect_uris.first?, scope: "api.current_user.show", state: "abc123" - ) + )) response.should send_json( 400, @@ -76,14 +74,13 @@ describe Shield::Api::Oauth::Authorization::Pipes do developer = UserFactory.create oauth_client = OauthClientFactory.create &.user_id(developer.id) - response = ApiClient.exec( - Spec::Api::Oauth::Authorization::Pipes, - client_id: oauth_client.id, + response = ApiClient.exec(Spec::Api::Oauth::Authorization::Pipes.with( + client_id: oauth_client.id.hexstring, code_challenge: "a1b2c3", redirect_uri: oauth_client.redirect_uris.first?, response_type: "code", state: "abc123" - ) + )) response.should send_json( 400, @@ -96,14 +93,13 @@ describe Shield::Api::Oauth::Authorization::Pipes do developer = UserFactory.create oauth_client = OauthClientFactory.create &.user_id(developer.id) - response = ApiClient.exec( - Spec::Api::Oauth::Authorization::Pipes, - client_id: oauth_client.id, + response = ApiClient.exec(Spec::Api::Oauth::Authorization::Pipes.with( + client_id: oauth_client.id.hexstring, code_challenge: "a1b2c3", redirect_uri: oauth_client.redirect_uris.first?, response_type: "code", scope: "api.current_user.show" - ) + )) response.should send_json( 400, @@ -118,15 +114,14 @@ describe Shield::Api::Oauth::Authorization::Pipes do developer = UserFactory.create oauth_client = OauthClientFactory.create &.user_id(developer.id) - response = ApiClient.exec( - Spec::Api::Oauth::Authorization::Pipes, - client_id: oauth_client.id, + response = ApiClient.exec(Spec::Api::Oauth::Authorization::Pipes.with( + client_id: oauth_client.id.hexstring, code_challenge: "a1b2c3", redirect_uri: oauth_client.redirect_uris.first?, response_type: "token", scope: "api.current_user.show", state: "abc123" - ) + )) response.should send_json( 400, @@ -141,14 +136,13 @@ describe Shield::Api::Oauth::Authorization::Pipes do developer = UserFactory.create oauth_client = OauthClientFactory.create &.user_id(developer.id) - response = ApiClient.exec( - Spec::Api::Oauth::Authorization::Pipes, - client_id: oauth_client.id, + response = ApiClient.exec(Spec::Api::Oauth::Authorization::Pipes.with( + client_id: oauth_client.id.hexstring, redirect_uri: oauth_client.redirect_uris.first?, response_type: "code", scope: "api.current_user.show", state: "abc123" - ) + )) response.should send_json( 400, @@ -163,16 +157,15 @@ describe Shield::Api::Oauth::Authorization::Pipes do developer = UserFactory.create oauth_client = OauthClientFactory.create &.user_id(developer.id) - response = ApiClient.exec( - Spec::Api::Oauth::Authorization::Pipes, - client_id: oauth_client.id, + response = ApiClient.exec(Spec::Api::Oauth::Authorization::Pipes.with( + client_id: oauth_client.id.hexstring, code_challenge: "a1b2c3", code_challenge_method: "S512", redirect_uri: oauth_client.redirect_uris.first?, response_type: "code", scope: "api.current_user.show", state: "abc123" - ) + )) response.should send_json( 400, @@ -189,15 +182,14 @@ describe Shield::Api::Oauth::Authorization::Pipes do oauth_client = OauthClientFactory.create &.user_id(developer.id) .redirect_uris(["https://example.com/oauth/callback"]) - response = ApiClient.exec( - Spec::Api::Oauth::Authorization::Pipes, - client_id: oauth_client.id, + response = ApiClient.exec(Spec::Api::Oauth::Authorization::Pipes.with( + client_id: oauth_client.id.hexstring, code_challenge: "a1b2c3", redirect_uri: "myapp://callback", response_type: "code", scope: "api.current_user.show", state: "abc123" - ) + )) response.should send_json( 400, @@ -212,15 +204,14 @@ describe Shield::Api::Oauth::Authorization::Pipes do developer = UserFactory.create oauth_client = OauthClientFactory.create &.user_id(developer.id) - response = ApiClient.exec( - Spec::Api::Oauth::Authorization::Pipes, - client_id: oauth_client.id, + response = ApiClient.exec(Spec::Api::Oauth::Authorization::Pipes.with( + client_id: oauth_client.id.hexstring, code_challenge: "a1b2c3", redirect_uri: oauth_client.redirect_uris.first?, response_type: "code", scope: "api.invalid.scope", state: "abc123" - ) + )) response.should send_json( 400, diff --git a/spec/shield/actions/login_pipes_spec.cr b/spec/shield/actions/login_pipes_spec.cr index 129b28f0..eeb7851d 100644 --- a/spec/shield/actions/login_pipes_spec.cr +++ b/spec/shield/actions/login_pipes_spec.cr @@ -98,7 +98,7 @@ describe Shield::LoginPipes do client = ApiClient.new client.browser_auth(user, password, ip_address, session) - sleep 3 + sleep 3.seconds response = client.exec(Users::Show.with(user_id: user.id)) @@ -127,27 +127,27 @@ describe Shield::LoginPipes do response = client.exec(Users::Show.with(user_id: user.id)) - sleep 1 + sleep 1.second client.headers("Cookie": response.headers["Set-Cookie"]) response = client.exec(Users::Show.with(user_id: user.id)) - sleep 1 + sleep 1.second client.headers("Cookie": response.headers["Set-Cookie"]) response = client.exec(Users::Show.with(user_id: user.id)) - sleep 1 + sleep 1.second client.headers("Cookie": response.headers["Set-Cookie"]) response = client.exec(Users::Show.with(user_id: user.id)) - sleep 1 + sleep 1.second client.headers("Cookie": response.headers["Set-Cookie"]) response = client.exec(Users::Show.with(user_id: user.id)) - sleep 1 + sleep 1.second client.headers("Cookie": response.headers["Set-Cookie"]) response = client.exec(Users::Show.with(user_id: user.id)) diff --git a/spec/shield/actions/oauth/pipes_spec.cr b/spec/shield/actions/oauth/pipes_spec.cr index ffbb42d3..99c07ed3 100644 --- a/spec/shield/actions/oauth/pipes_spec.cr +++ b/spec/shield/actions/oauth/pipes_spec.cr @@ -9,13 +9,13 @@ class Spec::Oauth::Pipes < ApiAction # before :oauth_handle_errors before :oauth_check_duplicate_params - param client_id : String? - param code_challenge : String? + param client_id : String? = nil + param code_challenge : String? = nil param code_challenge_method : String = "plain" - param redirect_uri : String? - param response_type : String? - param scope : String? - param state : String? + param redirect_uri : String? = nil + param response_type : String? = nil + param scope : String? = nil + param state : String? = nil get "/spec/api/oauth/pipes" do raise "Server error" @@ -32,15 +32,14 @@ describe Shield::Oauth::Pipes do developer = UserFactory.create oauth_client = OauthClientFactory.create &.user_id(developer.id) - response = ApiClient.exec( - Spec::Oauth::Pipes, - client_id: oauth_client.id, + response = ApiClient.exec(Spec::Oauth::Pipes.with( + client_id: oauth_client.id.hexstring, code_challenge: "a1b2c3", redirect_uri: oauth_client.redirect_uris.first?, response_type: "code", scope: "api.current_user.show", state: "abc123" - ) + )) response.should send_json( 500, @@ -74,15 +73,14 @@ describe Shield::Oauth::Pipes do describe "#oauth_validate_client_id" do it "validates client ID" do - response = ApiClient.exec( - Spec::Oauth::Pipes, - client_id: 23, + response = ApiClient.exec(Spec::Oauth::Pipes.with( + client_id: "23", code_challenge: "a1b2c3", redirect_uri: "myapp://callback", response_type: "code", scope: "api.current_user.show", state: "abc123" - ) + )) response.should send_json( 400, diff --git a/src/shield/actions/oauth/authorization/new.cr b/src/shield/actions/oauth/authorization/new.cr index 8a9a1cb9..80994bcd 100644 --- a/src/shield/actions/oauth/authorization/new.cr +++ b/src/shield/actions/oauth/authorization/new.cr @@ -13,12 +13,12 @@ module Shield::Oauth::Authorization::New before :oauth_validate_code_challenge_method before :oauth_require_logged_in - param client_id : String? - param code_challenge : String? + param client_id : String? = nil + param code_challenge : String? = nil param code_challenge_method : String = OauthGrantPkce::METHOD_PLAIN - param redirect_uri : String? - param response_type : String? - param scope : String? + param redirect_uri : String? = nil + param response_type : String? = nil + param scope : String? = nil # get "/oauth/authorization" do # operation = StartOauthGrant.new( diff --git a/src/shield/actions/oauth/authorize.cr b/src/shield/actions/oauth/authorize.cr index dca8d78d..4a1e65b0 100644 --- a/src/shield/actions/oauth/authorize.cr +++ b/src/shield/actions/oauth/authorize.cr @@ -13,13 +13,13 @@ module Shield::Oauth::Authorize macro included include Shield::Oauth::Authorization::Pipes - param client_id : String? - param code_challenge : String? - param code_challenge_method : String? - param redirect_uri : String? - param response_type : String? - param scope : String? - param state : String? + param client_id : String? = nil + param code_challenge : String? = nil + param code_challenge_method : String? = nil + param redirect_uri : String? = nil + param response_type : String? = nil + param scope : String? = nil + param state : String? = nil # get "/oauth/authorize" do # run_operation