Skip to content

Commit

Permalink
Add support for Lucky v1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
akadusei committed Oct 23, 2024
1 parent 74ebf0e commit 775602c
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 77 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions shard.latest.yml
Original file line number Diff line number Diff line change
@@ -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
75 changes: 33 additions & 42 deletions spec/shield/actions/api/oauth/authorization/pipes_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
12 changes: 6 additions & 6 deletions spec/shield/actions/login_pipes_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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))
Expand Down
26 changes: 12 additions & 14 deletions spec/shield/actions/oauth/pipes_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions src/shield/actions/oauth/authorization/new.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 7 additions & 7 deletions src/shield/actions/oauth/authorize.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 775602c

Please sign in to comment.