Skip to content

Commit

Permalink
feat: allow session credentials to be initalised without validating t…
Browse files Browse the repository at this point in the history
…he values
  • Loading branch information
RJPearson94 committed Dec 18, 2022
1 parent 961e9e9 commit c4add14
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# v0.24.0 (2022-12-18)

FEATURES

### SDK

- Allow initialisation of session credential without validating the supplied values. This is implemented because some tools may initialise the client before credentials are supplied

# v0.23.3 (2022-12-14)

FIXES
Expand Down
12 changes: 11 additions & 1 deletion session/credentials/credentials.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package credentials

// Credentials respresent the field necessary to authenticate against the Twilio APIs
// Credentials represents the field necessary to authenticate against the Twilio APIs
type Credentials struct {
AccountSid string
Username string
Expand All @@ -20,3 +20,13 @@ func New(creds TwilioCredentials) (*Credentials, error) {
Password: creds.password(),
}, nil
}

// NewWithNoValidation creates a new instance of credentials using the supplied twilio credentials.
// This skips validation as some tools may initialise the client before credentials are supplied
func NewWithNoValidation(creds TwilioCredentials) *Credentials {
return &Credentials{
AccountSid: creds.AccountSid(),
Username: creds.username(),
Password: creds.password(),
}
}
46 changes: 43 additions & 3 deletions session/credentials/tests/credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

var _ = Describe("Credentials", func() {
Describe("When invalid Account credential are supplied", func() {
Describe("When invalid Account credential are supplied (with validation)", func() {
Context("No Sid supplied", func() {
creds, err := credentials.New(credentials.Account{
AuthToken: "Test Token",
Expand Down Expand Up @@ -55,6 +55,46 @@ var _ = Describe("Credentials", func() {
})
})

Describe("When invalid Account credential are supplied (without validation)", func() {
Context("No Sid supplied", func() {
creds := credentials.NewWithNoValidation(credentials.Account{
AuthToken: "Test Token",
})

It("Then credentials are not nil", func() {
Expect(creds).ToNot(BeNil())
Expect(creds.AccountSid).To(Equal(""))
Expect(creds.Username).To(Equal(""))
Expect(creds.Password).To(Equal("Test Token"))
})
})

Context("No Auth Token supplied", func() {
creds := credentials.NewWithNoValidation(credentials.Account{
Sid: "ACxxxxxxxxxxx",
})

It("Then credentials are not nil", func() {
Expect(creds.AccountSid).To(Equal("ACxxxxxxxxxxx"))
Expect(creds.Username).To(Equal("ACxxxxxxxxxxx"))
Expect(creds.Password).To(Equal(""))
})
})

Context("An invalid sid format", func() {
creds := credentials.NewWithNoValidation(credentials.Account{
Sid: "Test Sid",
AuthToken: "Test Token",
})

It("Then credentials are not nil", func() {
Expect(creds.AccountSid).To(Equal("Test Sid"))
Expect(creds.Username).To(Equal("Test Sid"))
Expect(creds.Password).To(Equal("Test Token"))
})
})
})

Describe("When valid Account credential are supplied", func() {
creds, err := credentials.New(credentials.Account{
Sid: "ACxxxxxxxxxxx",
Expand All @@ -65,7 +105,7 @@ var _ = Describe("Credentials", func() {
Expect(err).To(BeNil())
})

It("Then credentials are nil", func() {
It("Then credentials are not nil", func() {
Expect(creds).ToNot(BeNil())
Expect(creds.Username).To(Equal("ACxxxxxxxxxxx"))
Expect(creds.Password).To(Equal("Test Token"))
Expand Down Expand Up @@ -167,7 +207,7 @@ var _ = Describe("Credentials", func() {
Expect(err).To(BeNil())
})

It("Then credentials are nil", func() {
It("Then credentials are not nil", func() {
Expect(creds).ToNot(BeNil())
Expect(creds.AccountSid).To(Equal("ACxxxxxxxxxxx"))
Expect(creds.Username).To(Equal("SKxxxxxxxxxxx"))
Expand Down

0 comments on commit c4add14

Please sign in to comment.