Skip to content

Commit

Permalink
fix: base64 decoding needs to use no padding (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
bludot authored Apr 28, 2022
1 parent 30ea24b commit 67076b7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
7 changes: 5 additions & 2 deletions mfa/mfa.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ func (m *Service) decodeJWT(jwt string) (*entities.JWTData, error) {
if len(base64Claims) != 3 {
return nil, errors.New("Invalid JWT")
}
claimsJson, _ := base64.StdEncoding.DecodeString(base64Claims[1])
err := json.Unmarshal(claimsJson, &decodedJWT)
claimsJson, err := base64.StdEncoding.WithPadding(base64.NoPadding).DecodeString(base64Claims[1])
if err != nil {
return nil, err
}
err = json.Unmarshal(claimsJson, &decodedJWT)
if err != nil {
return nil, err
}
Expand Down
14 changes: 7 additions & 7 deletions mfa/mfa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TestNewMFAService(t *testing.T) {
})

t.Run("MFA_Process", func(t *testing.T) {
validJWT := "nil.eyJmbG93IjoidGVzdCIsImNoYWxsZW5nZXMiOnsiZHVtbXkiOnsic3RhdHVzIjoicGVuZGluZyJ9fX0=."
validJWT := "nil.eyJmbG93IjoidGVzdCIsImNoYWxsZW5nZXMiOnsiZHVtbXkiOnsic3RhdHVzIjoicGVuZGluZyJ9fX0."
a := assert.New(t)
ctrl := gomock.NewController(t)
config := entities.Config{}
Expand Down Expand Up @@ -103,7 +103,7 @@ func TestNewMFAService(t *testing.T) {
})

t.Run("MFA_Process_invalid_jwt", func(t *testing.T) {
invalidJWT := "nil.eyJmbG93IjoidGVzdCIsImNoYWxsZW5nZXMiOnsiZHVtbXkiOnsic3RhdHVzIjoicGVuZGluZyJ9fQ==."
invalidJWT := "nil.eyJmbG93IjoidGVzdCIsImNoYWxsZW5nZXMiOnsiZHVtbXkiOnsic3RhdHVzIjoicGVuZGluZyJ9fQ."
a := assert.New(t)
ctrl := gomock.NewController(t)
config := entities.Config{}
Expand All @@ -124,7 +124,7 @@ func TestNewMFAService(t *testing.T) {
})

t.Run("MFA_Process_HandleSolve", func(t *testing.T) {
validJWT := "nil.eyJmbG93IjoidGVzdCIsImNoYWxsZW5nZXMiOnsiZHVtbXkiOnsic3RhdHVzIjoicGVuZGluZyJ9fX0=."
validJWT := "nil.eyJmbG93IjoidGVzdCIsImNoYWxsZW5nZXMiOnsiZHVtbXkiOnsic3RhdHVzIjoicGVuZGluZyJ9fX0."
a := assert.New(t)
ctrl := gomock.NewController(t)
config := entities.Config{}
Expand Down Expand Up @@ -161,7 +161,7 @@ func TestNewMFAService(t *testing.T) {
})

t.Run("MFA_Process_Solve_error", func(t *testing.T) {
validJWT := "nil.eyJmbG93IjoidGVzdCIsImNoYWxsZW5nZXMiOnsiZHVtbXkiOnsic3RhdHVzIjoicGVuZGluZyJ9fX0=."
validJWT := "nil.eyJmbG93IjoidGVzdCIsImNoYWxsZW5nZXMiOnsiZHVtbXkiOnsic3RhdHVzIjoicGVuZGluZyJ9fX0."
a := assert.New(t)
ctrl := gomock.NewController(t)
config := entities.Config{}
Expand Down Expand Up @@ -198,7 +198,7 @@ func TestNewMFAService(t *testing.T) {
})

t.Run("MFA_Request_handle_reference", func(t *testing.T) {
validJWT := "nil.eyJmbG93IjoidGVzdCIsImNoYWxsZW5nZXMiOnsiZHVtbXkiOnsic3RhdHVzIjoicGVuZGluZyJ9fX0=."
validJWT := "nil.eyJmbG93IjoidGVzdCIsImNoYWxsZW5nZXMiOnsiZHVtbXkiOnsic3RhdHVzIjoicGVuZGluZyJ9fX0."
a := assert.New(t)
ctrl := gomock.NewController(t)
config := entities.Config{}
Expand Down Expand Up @@ -354,7 +354,7 @@ func TestNewMFAService(t *testing.T) {
})

t.Run("MFA_Process_solve_error", func(t *testing.T) {
validJWT := "nil.eyJmbG93IjoidGVzdCIsImNoYWxsZW5nZXMiOnsiZHVtbXkiOnsic3RhdHVzIjoicGVuZGluZyJ9fX0=."
validJWT := "nil.eyJmbG93IjoidGVzdCIsImNoYWxsZW5nZXMiOnsiZHVtbXkiOnsic3RhdHVzIjoicGVuZGluZyJ9fX0."
a := assert.New(t)
ctrl := gomock.NewController(t)
config := entities.Config{}
Expand Down Expand Up @@ -390,7 +390,7 @@ func TestNewMFAService(t *testing.T) {
})

t.Run("MFA_Process_solve_no_token", func(t *testing.T) {
validJWT := "nil.eyJmbG93IjoidGVzdCIsImNoYWxsZW5nZXMiOnsiZHVtbXkiOnsic3RhdHVzIjoicGVuZGluZyJ9fX0=."
validJWT := "nil.eyJmbG93IjoidGVzdCIsImNoYWxsZW5nZXMiOnsiZHVtbXkiOnsic3RhdHVzIjoicGVuZGluZyJ9fX0."
a := assert.New(t)
ctrl := gomock.NewController(t)
config := entities.Config{}
Expand Down

0 comments on commit 67076b7

Please sign in to comment.