forked from juanfont/headscale
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix issue where some oidc claim bools are sent as string
Jumpcloud send invalid json, so we need to handle it. Fixes juanfont#2293 Signed-off-by: Kristoffer Dalby <[email protected]>
- Loading branch information
Showing
2 changed files
with
114 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package types | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
) | ||
|
||
func TestUnmarshallOIDCClaims(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
jsonstr string | ||
want OIDCClaims | ||
}{ | ||
{ | ||
name: "normal-bool", | ||
jsonstr: ` | ||
{ | ||
"sub": "test", | ||
"email": "[email protected]", | ||
"email_verified": true | ||
} | ||
`, | ||
want: OIDCClaims{ | ||
Sub: "test", | ||
Email: "[email protected]", | ||
EmailVerified: true, | ||
}, | ||
}, | ||
{ | ||
name: "string-bool-true", | ||
jsonstr: ` | ||
{ | ||
"sub": "test2", | ||
"email": "[email protected]", | ||
"email_verified": "true" | ||
} | ||
`, | ||
want: OIDCClaims{ | ||
Sub: "test2", | ||
Email: "[email protected]", | ||
EmailVerified: true, | ||
}, | ||
}, | ||
{ | ||
name: "string-bool-false", | ||
jsonstr: ` | ||
{ | ||
"sub": "test3", | ||
"email": "[email protected]", | ||
"email_verified": "false" | ||
} | ||
`, | ||
want: OIDCClaims{ | ||
Sub: "test3", | ||
Email: "[email protected]", | ||
EmailVerified: false, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
var got OIDCClaims | ||
if err := json.Unmarshal([]byte(tt.jsonstr), &got); err != nil { | ||
t.Errorf("UnmarshallOIDCClaims() error = %v", err) | ||
return | ||
} | ||
if diff := cmp.Diff(got, tt.want); diff != "" { | ||
t.Errorf("UnmarshallOIDCClaims() mismatch (-want +got):\n%s", diff) | ||
} | ||
}) | ||
} | ||
} |