Skip to content

Commit

Permalink
fix: bump pop to v5.2 (#1922)
Browse files Browse the repository at this point in the history
Closes #1892
  • Loading branch information
aeneasr committed Jun 22, 2020
1 parent b19b7cf commit 5097805
Show file tree
Hide file tree
Showing 44 changed files with 236 additions and 213 deletions.
4 changes: 2 additions & 2 deletions .schema/api.swagger.json
Expand Up @@ -2676,7 +2676,7 @@
"type": "string"
},
"client_id": {
"description": "ClientID is the id for this client.",
"description": "ID is the id for this client.",
"type": "string"
},
"client_name": {
Expand Down Expand Up @@ -2809,7 +2809,7 @@
}
},
"client_id": {
"description": "ClientID is aclient identifier for the OAuth 2.0 client that\nrequested this token.",
"description": "ID is aclient identifier for the OAuth 2.0 client that\nrequested this token.",
"type": "string"
},
"exp": {
Expand Down
6 changes: 3 additions & 3 deletions client/client.go
Expand Up @@ -37,8 +37,8 @@ import (
type Client struct {
PK int64 `json:"-" db:"pk"`

// ClientID is the id for this client.
ClientID string `json:"client_id" db:"id"`
// ID is the id for this client.
ID string `json:"client_id" db:"id"`

// Name is the human-readable string name of the client to be presented to the
// end-user during authorization.
Expand Down Expand Up @@ -203,7 +203,7 @@ func (Client) TableName() string {
}

func (c *Client) GetID() string {
return c.ClientID
return c.ID
}

func (c *Client) GetRedirectURIs() []string {
Expand Down
2 changes: 1 addition & 1 deletion client/client_test.go
Expand Up @@ -33,7 +33,7 @@ var _ fosite.Client = new(Client)

func TestClient(t *testing.T) {
c := &Client{
ClientID: "foo",
ID: "foo",
RedirectURIs: []string{"foo"},
Scope: "foo bar",
TokenEndpointAuthMethod: "none",
Expand Down
2 changes: 1 addition & 1 deletion client/handler.go
Expand Up @@ -149,7 +149,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request, ps httprouter.P
secret = c.Secret
}

c.ClientID = ps.ByName("id")
c.ID = ps.ByName("id")
if err := h.r.ClientValidator().Validate(&c); err != nil {
h.r.Writer().WriteError(w, r, err)
return
Expand Down
14 changes: 7 additions & 7 deletions client/manager_test_helpers.go
Expand Up @@ -39,7 +39,7 @@ func TestHelperClientAutoGenerateKey(k string, m Storage) func(t *testing.T) {
return func(t *testing.T) {
ctx := context.TODO()
c := &Client{
ClientID: "foo",
ID: "foo",
Secret: "secret",
RedirectURIs: []string{"http://redirect"},
TermsOfServiceURI: "foo",
Expand All @@ -54,7 +54,7 @@ func TestHelperClientAuthenticate(k string, m Manager) func(t *testing.T) {
return func(t *testing.T) {
ctx := context.TODO()
require.NoError(t, m.CreateClient(ctx, &Client{
ClientID: "1234321",
ID: "1234321",
Secret: "secret",
RedirectURIs: []string{"http://redirect"},
}))
Expand All @@ -75,7 +75,7 @@ func TestHelperCreateGetUpdateDeleteClient(k string, m Storage) func(t *testing.
assert.NotNil(t, err)

c := &Client{
ClientID: "1234",
ID: "1234",
Name: "name",
Secret: "secret",
RedirectURIs: []string{"http://redirect", "http://redirect1"},
Expand Down Expand Up @@ -114,7 +114,7 @@ func TestHelperCreateGetUpdateDeleteClient(k string, m Storage) func(t *testing.
}

assert.NoError(t, m.CreateClient(ctx, &Client{
ClientID: "2-1234",
ID: "2-1234",
Name: "name",
Secret: "secret",
RedirectURIs: []string{"http://redirect"},
Expand All @@ -130,8 +130,8 @@ func TestHelperCreateGetUpdateDeleteClient(k string, m Storage) func(t *testing.
ds, err := m.GetClients(ctx, 100, 0)
assert.NoError(t, err)
assert.Len(t, ds, 2)
assert.NotEqual(t, ds[0].ClientID, ds[1].ClientID)
assert.NotEqual(t, ds[0].ClientID, ds[1].ClientID)
assert.NotEqual(t, ds[0].ID, ds[1].ID)
assert.NotEqual(t, ds[0].ID, ds[1].ID)
// test if SecretExpiresAt was set properly
assert.Equal(t, ds[0].SecretExpiresAt, 0)
assert.Equal(t, ds[1].SecretExpiresAt, 1)
Expand All @@ -144,7 +144,7 @@ func TestHelperCreateGetUpdateDeleteClient(k string, m Storage) func(t *testing.
assert.NoError(t, err)

err = m.UpdateClient(ctx, &Client{
ClientID: "2-1234",
ID: "2-1234",
Name: "name-new",
Secret: "secret-new",
RedirectURIs: []string{"http://redirect/new"},
Expand Down
2 changes: 1 addition & 1 deletion client/validator.go
Expand Up @@ -70,7 +70,7 @@ func NewValidatorWithClient(conf Configuration, client *http.Client) *Validator

func (v *Validator) Validate(c *Client) error {
id := uuid.New()
c.ClientID = stringsx.Coalesce(c.ClientID, id)
c.ID = stringsx.Coalesce(c.ID, id)

if c.TokenEndpointAuthMethod == "" {
c.TokenEndpointAuthMethod = "client_secret_basic"
Expand Down
36 changes: 18 additions & 18 deletions client/validator_test.go
Expand Up @@ -53,59 +53,59 @@ func TestValidate(t *testing.T) {
{
in: new(Client),
check: func(t *testing.T, c *Client) {
assert.NotEmpty(t, c.ClientID)
assert.NotEmpty(t, c.ID)
assert.NotEmpty(t, c.GetID())
assert.Equal(t, c.GetID(), c.ClientID)
assert.Equal(t, c.GetID(), c.ID)
},
},
{
in: &Client{ClientID: "foo"},
in: &Client{ID: "foo"},
check: func(t *testing.T, c *Client) {
assert.Equal(t, c.GetID(), c.ClientID)
assert.Equal(t, c.GetID(), c.ID)
},
},
{
in: &Client{ClientID: "foo"},
in: &Client{ID: "foo"},
check: func(t *testing.T, c *Client) {
assert.Equal(t, c.GetID(), c.ClientID)
assert.Equal(t, c.GetID(), c.ID)
},
},
{
in: &Client{ClientID: "foo", UserinfoSignedResponseAlg: "foo"},
in: &Client{ID: "foo", UserinfoSignedResponseAlg: "foo"},
expectErr: true,
},
{
in: &Client{ClientID: "foo", TokenEndpointAuthMethod: "private_key_jwt"},
in: &Client{ID: "foo", TokenEndpointAuthMethod: "private_key_jwt"},
expectErr: true,
},
{
in: &Client{ClientID: "foo", JSONWebKeys: &x.JoseJSONWebKeySet{JSONWebKeySet: new(jose.JSONWebKeySet)}, JSONWebKeysURI: "asdf", TokenEndpointAuthMethod: "private_key_jwt"},
in: &Client{ID: "foo", JSONWebKeys: &x.JoseJSONWebKeySet{JSONWebKeySet: new(jose.JSONWebKeySet)}, JSONWebKeysURI: "asdf", TokenEndpointAuthMethod: "private_key_jwt"},
expectErr: true,
},
{
in: &Client{ClientID: "foo", JSONWebKeys: &x.JoseJSONWebKeySet{JSONWebKeySet: new(jose.JSONWebKeySet)}, TokenEndpointAuthMethod: "private_key_jwt", TokenEndpointAuthSigningAlgorithm: "HS256"},
in: &Client{ID: "foo", JSONWebKeys: &x.JoseJSONWebKeySet{JSONWebKeySet: new(jose.JSONWebKeySet)}, TokenEndpointAuthMethod: "private_key_jwt", TokenEndpointAuthSigningAlgorithm: "HS256"},
expectErr: true,
},
{
in: &Client{ClientID: "foo", PostLogoutRedirectURIs: []string{"https://bar/"}, RedirectURIs: []string{"https://foo/"}},
in: &Client{ID: "foo", PostLogoutRedirectURIs: []string{"https://bar/"}, RedirectURIs: []string{"https://foo/"}},
expectErr: true,
},
{
in: &Client{ClientID: "foo", PostLogoutRedirectURIs: []string{"http://foo/"}, RedirectURIs: []string{"https://foo/"}},
in: &Client{ID: "foo", PostLogoutRedirectURIs: []string{"http://foo/"}, RedirectURIs: []string{"https://foo/"}},
expectErr: true,
},
{
in: &Client{ClientID: "foo", PostLogoutRedirectURIs: []string{"https://foo:1234/"}, RedirectURIs: []string{"https://foo/"}},
in: &Client{ID: "foo", PostLogoutRedirectURIs: []string{"https://foo:1234/"}, RedirectURIs: []string{"https://foo/"}},
expectErr: true,
},
{
in: &Client{ClientID: "foo", PostLogoutRedirectURIs: []string{"https://foo/"}, RedirectURIs: []string{"https://foo/"}},
in: &Client{ID: "foo", PostLogoutRedirectURIs: []string{"https://foo/"}, RedirectURIs: []string{"https://foo/"}},
check: func(t *testing.T, c *Client) {
assert.Equal(t, []string{"https://foo/"}, []string(c.PostLogoutRedirectURIs))
},
},
{
in: &Client{ClientID: "foo"},
in: &Client{ID: "foo"},
check: func(t *testing.T, c *Client) {
assert.Equal(t, "public", c.SubjectType)
},
Expand All @@ -115,19 +115,19 @@ func TestValidate(t *testing.T) {
viper.Set(configuration.ViperKeySubjectTypesSupported, []string{"pairwise"})
return NewValidator(c)
},
in: &Client{ClientID: "foo"},
in: &Client{ID: "foo"},
check: func(t *testing.T, c *Client) {
assert.Equal(t, "pairwise", c.SubjectType)
},
},
{
in: &Client{ClientID: "foo", SubjectType: "pairwise"},
in: &Client{ID: "foo", SubjectType: "pairwise"},
check: func(t *testing.T, c *Client) {
assert.Equal(t, "pairwise", c.SubjectType)
},
},
{
in: &Client{ClientID: "foo", SubjectType: "foo"},
in: &Client{ID: "foo", SubjectType: "foo"},
expectErr: true,
},
} {
Expand Down
4 changes: 2 additions & 2 deletions cmd/cli/handler_migrate.go
Expand Up @@ -27,7 +27,7 @@ func (h *MigrateHandler) MigrateSQL(cmd *cobra.Command, args []string) {
var d driver.Driver

if flagx.MustGetBool(cmd, "read-from-env") {
d = driver.NewDefaultDriver(logrusx.New("",""), false, nil, "", "", "", false)
d = driver.NewDefaultDriver(logrusx.New("", ""), false, nil, "", "", "", false)
if len(d.Configuration().DSN()) == 0 {
fmt.Println(cmd.UsageString())
fmt.Println("")
Expand All @@ -42,7 +42,7 @@ func (h *MigrateHandler) MigrateSQL(cmd *cobra.Command, args []string) {
return
}
viper.Set(configuration.ViperKeyDSN, args[0])
d = driver.NewDefaultDriver(logrusx.New("",""), false, nil, "", "", "", false)
d = driver.NewDefaultDriver(logrusx.New("", ""), false, nil, "", "", "", false)
}

p := d.Registry().Persister()
Expand Down
6 changes: 3 additions & 3 deletions consent/handler_test.go
Expand Up @@ -107,7 +107,7 @@ func TestGetLogoutRequest(t *testing.T) {

if tc.exists {
require.NoError(t, reg.ConsentManager().CreateLogoutRequest(context.TODO(), &LogoutRequest{
Client: &client.Client{ClientID: "client" + key},
Client: &client.Client{ID: "client" + key},
Challenge: challenge,
WasUsed: tc.used,
}))
Expand Down Expand Up @@ -146,7 +146,7 @@ func TestGetLoginRequest(t *testing.T) {

if tc.exists {
require.NoError(t, reg.ConsentManager().CreateLoginRequest(context.TODO(), &LoginRequest{
Client: &client.Client{ClientID: "client" + key},
Client: &client.Client{ID: "client" + key},
Challenge: challenge,
WasHandled: tc.handled,
}))
Expand Down Expand Up @@ -185,7 +185,7 @@ func TestGetConsentRequest(t *testing.T) {

if tc.exists {
require.NoError(t, reg.ConsentManager().CreateConsentRequest(context.TODO(), &ConsentRequest{
Client: &client.Client{ClientID: "client" + key},
Client: &client.Client{ID: "client" + key},
Challenge: challenge,
WasHandled: tc.handled,
}))
Expand Down
14 changes: 7 additions & 7 deletions consent/manager_memory.go
Expand Up @@ -181,7 +181,7 @@ func (m *MemoryManager) GetConsentRequest(ctx context.Context, challenge string)
}
m.m["handledConsentRequests"].RUnlock()

c.Client.ClientID = c.Client.GetID()
c.Client.ID = c.Client.GetID()
return &c, nil
}

Expand Down Expand Up @@ -210,7 +210,7 @@ func (m *MemoryManager) VerifyAndInvalidateConsentRequest(ctx context.Context, v
return nil, err
}

c.Client.ClientID = c.Client.GetID()
c.Client.ID = c.Client.GetID()
h.ConsentRequest = &c
return &h, nil
}
Expand Down Expand Up @@ -260,7 +260,7 @@ func (m *MemoryManager) FindGrantedAndRememberedConsentRequests(ctx context.Cont
continue
}

cr.Client.ClientID = cr.Client.GetID()
cr.Client.ID = cr.Client.GetID()
c.ConsentRequest = cr
rs = append(rs, c)
}
Expand Down Expand Up @@ -301,7 +301,7 @@ func (m *MemoryManager) FindSubjectsGrantedConsentRequests(ctx context.Context,
continue
}

cr.Client.ClientID = cr.Client.GetID()
cr.Client.ID = cr.Client.GetID()
c.ConsentRequest = cr
rs = append(rs, c)
}
Expand Down Expand Up @@ -343,7 +343,7 @@ func (m *MemoryManager) CountSubjectsGrantedConsentRequests(ctx context.Context,
continue
}

cr.Client.ClientID = cr.Client.GetID()
cr.Client.ID = cr.Client.GetID()
c.ConsentRequest = cr
rs = append(rs, c)
}
Expand Down Expand Up @@ -420,7 +420,7 @@ func (m *MemoryManager) GetLoginRequest(ctx context.Context, challenge string) (
}
m.m["handledAuthRequests"].Unlock()

c.Client.ClientID = c.Client.GetID()
c.Client.ID = c.Client.GetID()
return &c, nil
}

Expand Down Expand Up @@ -450,7 +450,7 @@ func (m *MemoryManager) VerifyAndInvalidateLoginRequest(ctx context.Context, ver
return nil, err
}

c.Client.ClientID = c.Client.GetID()
c.Client.ID = c.Client.GetID()
h.LoginRequest = &c
return &h, nil
}
Expand Down

0 comments on commit 5097805

Please sign in to comment.