Skip to content

Commit 365c01c

Browse files
authored
fix: correct cognito auth fields names (#341)
This changes the field names to match the new Cognito auth fields, removing the redundantCognito prefix.
1 parent db416b5 commit 365c01c

File tree

3 files changed

+32
-27
lines changed

3 files changed

+32
-27
lines changed

.changeset/cruel-things-shave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"chainlink-deployments-framework": minor
3+
---
4+
5+
[Breaking] Change CognitoAuth field names

offchain/jd/cognito.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ type CognitoTokenSource struct {
3838
// CognitoAuth contains the Cognito authentication information required to generate a token from
3939
// Cognito.
4040
type CognitoAuth struct {
41-
AWSRegion string
42-
CognitoAppClientID string
43-
CognitoAppClientSecret string
44-
Username string
45-
Password string
41+
AWSRegion string
42+
AppClientID string
43+
AppClientSecret string
44+
Username string
45+
Password string
4646
}
4747

4848
// NewCognitoTokenSource creates a new CognitoTokenSource with the given CognitoAuth configuration.
@@ -72,7 +72,7 @@ func (c *CognitoTokenSource) Authenticate(ctx context.Context) error {
7272
// Authenticate the user
7373
input := &cognitoidentityprovider.InitiateAuthInput{
7474
AuthFlow: types.AuthFlowTypeUserPasswordAuth,
75-
ClientId: aws.String(c.auth.CognitoAppClientID),
75+
ClientId: aws.String(c.auth.AppClientID),
7676
AuthParameters: map[string]string{
7777
"USERNAME": c.auth.Username,
7878
"PASSWORD": c.auth.Password,
@@ -135,8 +135,8 @@ func (c *CognitoTokenSource) Token() (*oauth2.Token, error) {
135135
//
136136
// Returns the computed secret hash as a base64-encoded string.
137137
func (c *CognitoTokenSource) secretHash() string {
138-
hmac := hmac.New(sha256.New, []byte(c.auth.CognitoAppClientSecret))
139-
message := []byte(c.auth.Username + c.auth.CognitoAppClientID)
138+
hmac := hmac.New(sha256.New, []byte(c.auth.AppClientSecret))
139+
message := []byte(c.auth.Username + c.auth.AppClientID)
140140
hmac.Write(message)
141141
dataHmac := hmac.Sum(nil)
142142

offchain/jd/cognito_test.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ func Test_NewCognitoTokenSource(t *testing.T) {
2626
t.Parallel()
2727

2828
auth := CognitoAuth{
29-
AWSRegion: "us-east-1",
30-
CognitoAppClientID: "test-client-id",
31-
CognitoAppClientSecret: "test-client-secret",
32-
Username: "testuser",
33-
Password: "testpass",
29+
AWSRegion: "us-east-1",
30+
AppClientID: "test-client-id",
31+
AppClientSecret: "test-client-secret",
32+
Username: "testuser",
33+
Password: "testpass",
3434
}
3535

3636
tokenSource := NewCognitoTokenSource(auth)
@@ -45,11 +45,11 @@ func Test_CognitoTokenSource_Authenticate(t *testing.T) {
4545
t.Parallel()
4646

4747
auth := CognitoAuth{
48-
AWSRegion: "us-east-1",
49-
CognitoAppClientID: "test-client-id",
50-
CognitoAppClientSecret: "test-client-secret",
51-
Username: "testuser",
52-
Password: "testpass",
48+
AWSRegion: "us-east-1",
49+
AppClientID: "test-client-id",
50+
AppClientSecret: "test-client-secret",
51+
Username: "testuser",
52+
Password: "testpass",
5353
}
5454

5555
tests := []struct {
@@ -72,7 +72,7 @@ func Test_CognitoTokenSource_Authenticate(t *testing.T) {
7272
}
7373

7474
client.EXPECT().InitiateAuth(mock.Anything, mock.MatchedBy(func(input *cognitoidentityprovider.InitiateAuthInput) bool {
75-
return *input.ClientId == auth.CognitoAppClientID &&
75+
return *input.ClientId == auth.AppClientID &&
7676
input.AuthFlow == types.AuthFlowTypeUserPasswordAuth &&
7777
input.AuthParameters["USERNAME"] == auth.Username &&
7878
input.AuthParameters["PASSWORD"] == auth.Password &&
@@ -175,11 +175,11 @@ func Test_CognitoTokenSource_Token(t *testing.T) {
175175

176176
client := mocks.NewMockCognitoClient(t)
177177
auth := CognitoAuth{
178-
AWSRegion: "us-east-1",
179-
CognitoAppClientID: "test-client-id",
180-
CognitoAppClientSecret: "test-client-secret",
181-
Username: "testuser",
182-
Password: "testpass",
178+
AWSRegion: "us-east-1",
179+
AppClientID: "test-client-id",
180+
AppClientSecret: "test-client-secret",
181+
Username: "testuser",
182+
Password: "testpass",
183183
}
184184

185185
source := newCognitoTokenSourceWithClient(auth, client)
@@ -206,9 +206,9 @@ func Test_CognitoTokenSource_secretHash(t *testing.T) {
206206

207207
// Test with static values to ensure the hash calculation is correct
208208
auth := CognitoAuth{
209-
CognitoAppClientID: "clientid",
210-
CognitoAppClientSecret: "secret",
211-
Username: "user",
209+
AppClientID: "clientid",
210+
AppClientSecret: "secret",
211+
Username: "user",
212212
}
213213

214214
tokenSource := NewCognitoTokenSource(auth)

0 commit comments

Comments
 (0)