Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix UpdateCredential func #209

Merged
merged 1 commit into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions management/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,24 @@ func (m *ClientManager) CreateCredential(clientID string, credential *Credential

// UpdateCredential updates a client application's client credential expiry.
func (m *ClientManager) UpdateCredential(clientID, credentialID string, credential *Credential, opts ...RequestOption) error {
credential = &Credential{ExpiresAt: credential.ExpiresAt} // The API only accepts the expires_at property.
return m.Request("PATCH", m.URI("clients", clientID, "credentials", credentialID), credential, opts...)
credentialClone := &Credential{ExpiresAt: credential.ExpiresAt} // The API only accepts the expires_at property.

err := m.Request("PATCH", m.URI("clients", clientID, "credentials", credentialID), credentialClone, opts...)
if err != nil {
return err
}

credential.ID = credentialClone.ID
credential.Name = credentialClone.Name
credential.CredentialType = credentialClone.CredentialType
credential.KeyID = credentialClone.KeyID
credential.Algorithm = credentialClone.Algorithm
credential.CreatedAt = credentialClone.CreatedAt
credential.UpdatedAt = credentialClone.UpdatedAt
credential.ExpiresAt = credentialClone.ExpiresAt
// PEM and ParseExpiryFromCert don't get returned.

return nil
}

// ListCredentials lists all client credentials associated with the client application.
Expand Down
8 changes: 7 additions & 1 deletion management/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,16 @@ func TestClient_UpdateCredential(t *testing.T) {
expiresAt := time.Now().Add(time.Minute * 10)
expectedCredential.ExpiresAt = &expiresAt

err := api.Client.UpdateCredential(expectedClient.GetClientID(), expectedCredential.GetID(), expectedCredential)
pem := expectedCredential.GetPEM()
credentialID := expectedCredential.GetID()
expectedCredential.ID = nil

err := api.Client.UpdateCredential(expectedClient.GetClientID(), credentialID, expectedCredential)

assert.NoError(t, err)
assert.Equal(t, expectedCredential.GetExpiresAt(), expiresAt)
assert.Equal(t, expectedCredential.GetID(), credentialID) // Check that we unmarshall the result into this struct.
assert.Equal(t, expectedCredential.GetPEM(), pem)
}

func TestClient_DeleteCredential(t *testing.T) {
Expand Down