Skip to content

Commit

Permalink
restore the grant types literals in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wood-push-melon committed Apr 11, 2024
1 parent 9e5f7e2 commit d737e9d
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 85 deletions.
68 changes: 34 additions & 34 deletions handler/oauth2/flow_authorize_code_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ func TestAuthorizeCode_PopulateTokenEndpointResponse(t *testing.T) {
{
description: "should fail because not responsible for handling the request",
areq: &fosite.AccessRequest{
GrantTypes: fosite.Arguments{string(fosite.GrantTypeImplicit)},
GrantTypes: fosite.Arguments{"implicit"},
Request: fosite.Request{
Client: &fosite.DefaultClient{
GrantTypes: fosite.Arguments{string(fosite.GrantTypeAuthorizationCode)},
GrantTypes: fosite.Arguments{"authorization_code"},
},
Session: &fosite.DefaultSession{},
RequestedAt: time.Now().UTC(),
Expand All @@ -53,11 +53,11 @@ func TestAuthorizeCode_PopulateTokenEndpointResponse(t *testing.T) {
{
description: "should fail because authorization code cannot be retrieved",
areq: &fosite.AccessRequest{
GrantTypes: fosite.Arguments{string(fosite.GrantTypeAuthorizationCode)},
GrantTypes: fosite.Arguments{"authorization_code"},
Request: fosite.Request{
Form: url.Values{},
Client: &fosite.DefaultClient{
GrantTypes: fosite.Arguments{string(fosite.GrantTypeAuthorizationCode)},
GrantTypes: fosite.Arguments{"authorization_code"},
},
Session: &fosite.DefaultSession{},
RequestedAt: time.Now().UTC(),
Expand All @@ -73,12 +73,12 @@ func TestAuthorizeCode_PopulateTokenEndpointResponse(t *testing.T) {
{
description: "should pass with offline scope and refresh token grant type",
areq: &fosite.AccessRequest{
GrantTypes: fosite.Arguments{string(fosite.GrantTypeAuthorizationCode)},
GrantTypes: fosite.Arguments{"authorization_code"},
Request: fosite.Request{
Form: url.Values{},
Client: &fosite.DefaultClient{
ID: "foo",
GrantTypes: fosite.Arguments{string(fosite.GrantTypeAuthorizationCode), string(fosite.GrantTypeRefreshToken)},
GrantTypes: fosite.Arguments{"authorization_code", "refresh_token"},
},
Session: &fosite.DefaultSession{},
RequestedAt: time.Now().UTC(),
Expand All @@ -88,7 +88,7 @@ func TestAuthorizeCode_PopulateTokenEndpointResponse(t *testing.T) {
Request: fosite.Request{
Client: &fosite.DefaultClient{
ID: "foo",
GrantTypes: []string{string(fosite.GrantTypeAuthorizationCode)},
GrantTypes: []string{"authorization_code"},
},
RequestedScope: fosite.Arguments{"foo", "bar", "offline"},
GrantedScope: fosite.Arguments{"foo", "offline"},
Expand All @@ -114,12 +114,12 @@ func TestAuthorizeCode_PopulateTokenEndpointResponse(t *testing.T) {
{
description: "should pass with refresh token grant type",
areq: &fosite.AccessRequest{
GrantTypes: fosite.Arguments{string(fosite.GrantTypeAuthorizationCode)},
GrantTypes: fosite.Arguments{"authorization_code"},
Request: fosite.Request{
Form: url.Values{},
Client: &fosite.DefaultClient{
ID: "foo",
GrantTypes: fosite.Arguments{string(fosite.GrantTypeAuthorizationCode), string(fosite.GrantTypeRefreshToken)},
GrantTypes: fosite.Arguments{"authorization_code", "refresh_token"},
},
Session: &fosite.DefaultSession{},
RequestedAt: time.Now().UTC(),
Expand All @@ -129,7 +129,7 @@ func TestAuthorizeCode_PopulateTokenEndpointResponse(t *testing.T) {
Request: fosite.Request{
Client: &fosite.DefaultClient{
ID: "foo",
GrantTypes: []string{string(fosite.GrantTypeAuthorizationCode)},
GrantTypes: []string{"authorization_code"},
},
RequestedScope: fosite.Arguments{"foo", "bar"},
GrantedScope: fosite.Arguments{"foo"},
Expand All @@ -156,7 +156,7 @@ func TestAuthorizeCode_PopulateTokenEndpointResponse(t *testing.T) {
{
description: "pass and response should not have refresh token",
areq: &fosite.AccessRequest{
GrantTypes: fosite.Arguments{string(fosite.GrantTypeAuthorizationCode)},
GrantTypes: fosite.Arguments{"authorization_code"},
Request: fosite.Request{
Form: url.Values{},
Client: &fosite.DefaultClient{
Expand All @@ -171,7 +171,7 @@ func TestAuthorizeCode_PopulateTokenEndpointResponse(t *testing.T) {
Request: fosite.Request{
Client: &fosite.DefaultClient{
ID: "foo",
GrantTypes: []string{string(fosite.GrantTypeDeviceCode)},
GrantTypes: []string{"authorization_code"},
},
RequestedScope: fosite.Arguments{"foo", "bar"},
GrantedScope: fosite.Arguments{"foo"},
Expand Down Expand Up @@ -274,11 +274,11 @@ func TestAuthorizeCode_HandleTokenEndpointRequest(t *testing.T) {
{
description: "should fail because not responsible for handling the request",
areq: &fosite.AccessRequest{
GrantTypes: fosite.Arguments{string(fosite.GrantTypeImplicit)},
GrantTypes: fosite.Arguments{"implicit"},
Request: fosite.Request{
Client: &fosite.DefaultClient{
ID: "foo",
GrantTypes: []string{string(fosite.GrantTypeAuthorizationCode)},
GrantTypes: []string{"authorization_code"},
},
Form: url.Values{"redirect_uri": []string{"request-redir"}},
Session: &fosite.DefaultSession{},
Expand Down Expand Up @@ -306,11 +306,11 @@ func TestAuthorizeCode_HandleTokenEndpointRequest(t *testing.T) {
{
description: "should fail because authorization code cannot be retrieved",
areq: &fosite.AccessRequest{
GrantTypes: fosite.Arguments{string(fosite.GrantTypeAuthorizationCode)},
GrantTypes: fosite.Arguments{"authorization_code"},
Request: fosite.Request{
Client: &fosite.DefaultClient{
ID: "foo",
GrantTypes: []string{string(fosite.GrantTypeAuthorizationCode)},
GrantTypes: []string{"authorization_code"},
},
Form: url.Values{"redirect_uri": []string{"request-redir"}},
Session: &fosite.DefaultSession{},
Expand All @@ -327,15 +327,15 @@ func TestAuthorizeCode_HandleTokenEndpointRequest(t *testing.T) {
{
description: "should fail because authorization code is expired",
areq: &fosite.AccessRequest{
GrantTypes: fosite.Arguments{string(fosite.GrantTypeAuthorizationCode)},
GrantTypes: fosite.Arguments{"authorization_code"},
Request: fosite.Request{
Form: url.Values{
"code": {"foo.bar"},
"redirect_uri": []string{"request-redir"},
},
Client: &fosite.DefaultClient{
ID: "foo",
GrantTypes: []string{string(fosite.GrantTypeAuthorizationCode)},
GrantTypes: []string{"authorization_code"},
},
Session: &fosite.DefaultSession{},
RequestedAt: time.Now().UTC(),
Expand All @@ -345,7 +345,7 @@ func TestAuthorizeCode_HandleTokenEndpointRequest(t *testing.T) {
Request: fosite.Request{
Client: &fosite.DefaultClient{
ID: "foo",
GrantTypes: []string{string(fosite.GrantTypeAuthorizationCode)},
GrantTypes: []string{"authorization_code"},
},
Form: url.Values{"redirect_uri": []string{"request-redir"}},
RequestedScope: fosite.Arguments{"foo"},
Expand All @@ -370,11 +370,11 @@ func TestAuthorizeCode_HandleTokenEndpointRequest(t *testing.T) {
{
description: "should fail because client mismatch",
areq: &fosite.AccessRequest{
GrantTypes: fosite.Arguments{string(fosite.GrantTypeAuthorizationCode)},
GrantTypes: fosite.Arguments{"authorization_code"},
Request: fosite.Request{
Client: &fosite.DefaultClient{
ID: "foo",
GrantTypes: []string{string(fosite.GrantTypeAuthorizationCode)},
GrantTypes: []string{"authorization_code"},
},
Form: url.Values{"redirect_uri": []string{"request-redir"}},
Session: &fosite.DefaultSession{},
Expand All @@ -385,7 +385,7 @@ func TestAuthorizeCode_HandleTokenEndpointRequest(t *testing.T) {
Request: fosite.Request{
Client: &fosite.DefaultClient{
ID: "bar",
GrantTypes: []string{string(fosite.GrantTypeAuthorizationCode)},
GrantTypes: []string{"authorization_code"},
},
Form: url.Values{"redirect_uri": []string{"request-redir"}},
RequestedScope: fosite.Arguments{"foo"},
Expand All @@ -409,11 +409,11 @@ func TestAuthorizeCode_HandleTokenEndpointRequest(t *testing.T) {
{
description: "should fail because redirect uri was set during /authorize call, but not in /token call",
areq: &fosite.AccessRequest{
GrantTypes: fosite.Arguments{string(fosite.GrantTypeAuthorizationCode)},
GrantTypes: fosite.Arguments{"authorization_code"},
Request: fosite.Request{
Client: &fosite.DefaultClient{
ID: "foo",
GrantTypes: []string{string(fosite.GrantTypeAuthorizationCode)},
GrantTypes: []string{"authorization_code"},
},
Form: url.Values{},
Session: &fosite.DefaultSession{},
Expand All @@ -424,7 +424,7 @@ func TestAuthorizeCode_HandleTokenEndpointRequest(t *testing.T) {
Request: fosite.Request{
Client: &fosite.DefaultClient{
ID: "foo",
GrantTypes: []string{string(fosite.GrantTypeAuthorizationCode)},
GrantTypes: []string{"authorization_code"},
},
Form: url.Values{"redirect_uri": []string{"request-redir"}},
RequestedScope: fosite.Arguments{"foo"},
Expand All @@ -448,11 +448,11 @@ func TestAuthorizeCode_HandleTokenEndpointRequest(t *testing.T) {
{
description: "should pass",
areq: &fosite.AccessRequest{
GrantTypes: fosite.Arguments{string(fosite.GrantTypeAuthorizationCode)},
GrantTypes: fosite.Arguments{"authorization_code"},
Request: fosite.Request{
Client: &fosite.DefaultClient{
ID: "foo",
GrantTypes: []string{string(fosite.GrantTypeAuthorizationCode)},
GrantTypes: []string{"authorization_code"},
},
Form: url.Values{"redirect_uri": []string{"request-redir"}},
Session: &fosite.DefaultSession{},
Expand All @@ -463,7 +463,7 @@ func TestAuthorizeCode_HandleTokenEndpointRequest(t *testing.T) {
Request: fosite.Request{
Client: &fosite.DefaultClient{
ID: "foo",
GrantTypes: []string{string(fosite.GrantTypeAuthorizationCode)},
GrantTypes: []string{"authorization_code"},
},
Form: url.Values{"redirect_uri": []string{"request-redir"}},
RequestedScope: fosite.Arguments{"foo"},
Expand All @@ -483,12 +483,12 @@ func TestAuthorizeCode_HandleTokenEndpointRequest(t *testing.T) {
{
description: "should fail because code has been used already",
areq: &fosite.AccessRequest{
GrantTypes: fosite.Arguments{string(fosite.GrantTypeAuthorizationCode)},
GrantTypes: fosite.Arguments{"authorization_code"},
Request: fosite.Request{
Form: url.Values{"redirect_uri": []string{"request-redir"}},
Client: &fosite.DefaultClient{
ID: "foo",
GrantTypes: fosite.Arguments{string(fosite.GrantTypeAuthorizationCode)},
GrantTypes: fosite.Arguments{"authorization_code"},
},
Session: &fosite.DefaultSession{},
RequestedAt: time.Now().UTC(),
Expand All @@ -498,7 +498,7 @@ func TestAuthorizeCode_HandleTokenEndpointRequest(t *testing.T) {
Request: fosite.Request{
Client: &fosite.DefaultClient{
ID: "foo",
GrantTypes: []string{string(fosite.GrantTypeAuthorizationCode)},
GrantTypes: []string{"authorization_code"},
},
Form: url.Values{"redirect_uri": []string{"request-redir"}},
RequestedScope: fosite.Arguments{"foo"},
Expand Down Expand Up @@ -552,7 +552,7 @@ func TestAuthorizeCodeTransactional_HandleTokenEndpointRequest(t *testing.T) {
Request: fosite.Request{
Client: &fosite.DefaultClient{
ID: "foo",
GrantTypes: []string{string(fosite.GrantTypeDeviceCode)},
GrantTypes: []string{"authorization_code"},
},
RequestedScope: fosite.Arguments{"foo", "offline"},
GrantedScope: fosite.Arguments{"foo", "offline"},
Expand All @@ -562,10 +562,10 @@ func TestAuthorizeCodeTransactional_HandleTokenEndpointRequest(t *testing.T) {
}

areq := &fosite.AccessRequest{
GrantTypes: fosite.Arguments{string(fosite.GrantTypeAuthorizationCode)},
GrantTypes: fosite.Arguments{"authorization_code"},
Request: fosite.Request{
Client: &fosite.DefaultClient{
GrantTypes: fosite.Arguments{string(fosite.GrantTypeAuthorizationCode), string(fosite.GrantTypeRefreshToken)},
GrantTypes: fosite.Arguments{"authorization_code", "refresh_token"},
},
Session: &fosite.DefaultSession{},
RequestedAt: time.Now().UTC(),
Expand Down
4 changes: 2 additions & 2 deletions handler/openid/flow_device_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestDeviceAuth_HandleDeviceEndpointRequest(t *testing.T) {

client := &fosite.DefaultClient{
ID: "foo",
GrantTypes: fosite.Arguments{string(fosite.GrantTypeDeviceCode)},
GrantTypes: fosite.Arguments{"urn:ietf:params:oauth:grant-type:device_code"},
}

testCases := []struct {
Expand All @@ -88,7 +88,7 @@ func TestDeviceAuth_HandleDeviceEndpointRequest(t *testing.T) {
Request: fosite.Request{
GrantedScope: fosite.Arguments{"openid", "email"},
Client: &fosite.DefaultClient{
GrantTypes: []string{string(fosite.GrantTypeAuthorizationCode)},
GrantTypes: []string{"authorization_code"},
},
},
},
Expand Down
20 changes: 10 additions & 10 deletions handler/openid/flow_device_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func TestDeviceToken_PopulateTokenEndpointResponse(t *testing.T) {

client := &fosite.DefaultClient{
ID: "foo",
GrantTypes: fosite.Arguments{string(fosite.GrantTypeDeviceCode)},
GrantTypes: fosite.Arguments{"urn:ietf:params:oauth:grant-type:device_code"},
}

testCases := []struct {
Expand All @@ -95,7 +95,7 @@ func TestDeviceToken_PopulateTokenEndpointResponse(t *testing.T) {
{
description: "should fail because the grant type is invalid",
areq: &fosite.AccessRequest{
GrantTypes: fosite.Arguments{string(fosite.GrantTypeAuthorizationCode)},
GrantTypes: fosite.Arguments{"authorization_code"},
Request: fosite.Request{
Form: url.Values{"device_code": []string{"device_code"}},
Session: session,
Expand All @@ -107,7 +107,7 @@ func TestDeviceToken_PopulateTokenEndpointResponse(t *testing.T) {
{
description: "should fail because session not found",
areq: &fosite.AccessRequest{
GrantTypes: fosite.Arguments{string(fosite.GrantTypeDeviceCode)},
GrantTypes: fosite.Arguments{"urn:ietf:params:oauth:grant-type:device_code"},
Request: fosite.Request{
Form: url.Values{"device_code": []string{"device_code"}},
Session: session,
Expand All @@ -122,7 +122,7 @@ func TestDeviceToken_PopulateTokenEndpointResponse(t *testing.T) {
{
description: "should fail because session lookup fails",
areq: &fosite.AccessRequest{
GrantTypes: fosite.Arguments{string(fosite.GrantTypeDeviceCode)},
GrantTypes: fosite.Arguments{"urn:ietf:params:oauth:grant-type:device_code"},
Request: fosite.Request{
Form: url.Values{"device_code": []string{"device_code"}},
Session: session,
Expand All @@ -136,7 +136,7 @@ func TestDeviceToken_PopulateTokenEndpointResponse(t *testing.T) {
{
description: "should fail because auth request grant scope is invalid",
areq: &fosite.AccessRequest{
GrantTypes: fosite.Arguments{string(fosite.GrantTypeDeviceCode)},
GrantTypes: fosite.Arguments{"urn:ietf:params:oauth:grant-type:device_code"},
Request: fosite.Request{
Form: url.Values{"device_code": []string{"device_code"}},
Session: session,
Expand All @@ -156,10 +156,10 @@ func TestDeviceToken_PopulateTokenEndpointResponse(t *testing.T) {
{
description: "should fail because auth request's client grant type is invalid",
areq: &fosite.AccessRequest{
GrantTypes: fosite.Arguments{string(fosite.GrantTypeDeviceCode)},
GrantTypes: fosite.Arguments{"urn:ietf:params:oauth:grant-type:device_code"},
Request: fosite.Request{
Client: &fosite.DefaultClient{
GrantTypes: fosite.Arguments{string(fosite.GrantTypeAuthorizationCode)},
GrantTypes: fosite.Arguments{"authorization_code"},
},
Form: url.Values{"device_code": []string{"device_code"}},
Session: session,
Expand All @@ -179,7 +179,7 @@ func TestDeviceToken_PopulateTokenEndpointResponse(t *testing.T) {
{
description: "should fail because auth request is missing session",
areq: &fosite.AccessRequest{
GrantTypes: fosite.Arguments{string(fosite.GrantTypeDeviceCode)},
GrantTypes: fosite.Arguments{"urn:ietf:params:oauth:grant-type:device_code"},
Request: fosite.Request{
Client: client,
Form: url.Values{"device_code": []string{"device_code"}},
Expand All @@ -199,7 +199,7 @@ func TestDeviceToken_PopulateTokenEndpointResponse(t *testing.T) {
{
description: "should fail because auth request session is missing subject claims",
areq: &fosite.AccessRequest{
GrantTypes: fosite.Arguments{string(fosite.GrantTypeDeviceCode)},
GrantTypes: fosite.Arguments{"urn:ietf:params:oauth:grant-type:device_code"},
Request: fosite.Request{
Client: client,
Form: url.Values{"device_code": []string{"device_code"}},
Expand All @@ -220,7 +220,7 @@ func TestDeviceToken_PopulateTokenEndpointResponse(t *testing.T) {
{
description: "should pass",
areq: &fosite.AccessRequest{
GrantTypes: fosite.Arguments{string(fosite.GrantTypeDeviceCode)},
GrantTypes: fosite.Arguments{"urn:ietf:params:oauth:grant-type:device_code"},
Request: fosite.Request{
Client: client,
Form: url.Values{"device_code": []string{"device_code"}},
Expand Down
Loading

0 comments on commit d737e9d

Please sign in to comment.