|
|
@@ -40,6 +40,7 @@ import (
|
|
|
"github.com/smallstep/certificates/acme/wire"
|
|
|
"github.com/smallstep/certificates/authority/config"
|
|
|
"github.com/smallstep/certificates/authority/provisioner"
|
|
|
+ wireprovisioner "github.com/smallstep/certificates/authority/provisioner/wire"
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
"github.com/stretchr/testify/require"
|
|
|
)
|
|
|
@@ -4371,3 +4372,85 @@ MCowBQYDK2VwAyEAB2IYqBWXAouDt3WcCZgCM3t9gumMEKMlgMsGenSu+fA=
|
|
|
assert.Equal(t, "wire", dt["team"].(string))
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func createWireOptions(t *testing.T, transformTemplate string) *wireprovisioner.Options {
|
|
|
+ t.Helper()
|
|
|
+ fakeKey := `
|
|
|
+-----BEGIN PUBLIC KEY-----
|
|
|
+MCowBQYDK2VwAyEA5c+4NKZSNQcR1T8qN6SjwgdPZQ0Ge12Ylx/YeGAJ35k=
|
|
|
+-----END PUBLIC KEY-----`
|
|
|
+ opts := &wireprovisioner.Options{
|
|
|
+ OIDC: &wireprovisioner.OIDCOptions{
|
|
|
+ Provider: &wireprovisioner.Provider{
|
|
|
+ IssuerURL: "https://issuer.example.com",
|
|
|
+ AuthURL: "",
|
|
|
+ TokenURL: "",
|
|
|
+ JWKSURL: "",
|
|
|
+ UserInfoURL: "",
|
|
|
+ Algorithms: []string{},
|
|
|
+ },
|
|
|
+ Config: &wireprovisioner.Config{
|
|
|
+ ClientID: "unit test",
|
|
|
+ SignatureAlgorithms: []string{},
|
|
|
+ SkipClientIDCheck: true,
|
|
|
+ SkipExpiryCheck: true,
|
|
|
+ SkipIssuerCheck: true,
|
|
|
+ InsecureSkipSignatureCheck: true,
|
|
|
+ Now: time.Now,
|
|
|
+ },
|
|
|
+ TransformTemplate: transformTemplate,
|
|
|
+ },
|
|
|
+ DPOP: &wireprovisioner.DPOPOptions{
|
|
|
+ SigningKey: []byte(fakeKey),
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+ err := opts.Validate()
|
|
|
+ require.NoError(t, err)
|
|
|
+
|
|
|
+ return opts
|
|
|
+}
|
|
|
+
|
|
|
+func Test_idTokenTransformation(t *testing.T) {
|
|
|
+ // {"name": "wireapp://%40alice_wire@wire.com", "handle": "Alice Smith", "iss": "http://dex:15818/dex"}
|
|
|
+ idTokenString := `eyJhbGciOiJSUzI1NiIsImtpZCI6IjZhNDZlYzQ3YTQzYWI1ZTc4NzU3MzM5NWY1MGY4ZGQ5MWI2OTM5MzcifQ.eyJpc3MiOiJodHRwOi8vZGV4OjE1ODE4L2RleCIsInN1YiI6IkNqcDNhWEpsWVhCd09pOHZTMmh0VjBOTFpFTlRXakoyT1dWTWFHRk9XVlp6WnlFeU5UZzFNVEpoT0RRek5qTXhaV1V6UUhkcGNtVXVZMjl0RWdSc1pHRnciLCJhdWQiOiJ3aXJlYXBwIiwiZXhwIjoxNzA1MDkxNTYyLCJpYXQiOjE3MDUwMDUxNjIsIm5vbmNlIjoib0VjUzBRQUNXLVIyZWkxS09wUmZ2QSIsImF0X2hhc2giOiJoYzk0NmFwS25FeEV5TDVlSzJZMzdRIiwiY19oYXNoIjoidmRubFp2V1d1bVd1Z2NYR1JpOU5FUSIsIm5hbWUiOiJ3aXJlYXBwOi8vJTQwYWxpY2Vfd2lyZUB3aXJlLmNvbSIsInByZWZlcnJlZF91c2VybmFtZSI6IkFsaWNlIFNtaXRoIn0.aEBhWJugBJ9J_0L_4odUCg8SR8HMXVjd__X8uZRo42BSJQQO7-wdpy0jU3S4FOX9fQKr68wD61gS_QsnhfiT7w9U36mLpxaYlNVDCYfpa-gklVFit_0mjUOukXajTLK6H527TGiSss8z22utc40ckS1SbZa2BzKu3yOcqnFHUQwQc5sLYfpRABTB6WBoYFtnWDzdpyWJDaOzz7lfKYv2JBnf9vV8u8SYm-6gNKgtiQ3UUnjhIVUjdfHet2BMvmV2ooZ8V441RULCzKKG_sWZba-D_k_TOnSholGobtUOcKHlmVlmfUe8v7kuyBdhbPcembfgViaNldLQGKZjZfgvLg`
|
|
|
+ var claims struct {
|
|
|
+ Name string `json:"name,omitempty"`
|
|
|
+ Handle string `json:"preferred_username,omitempty"`
|
|
|
+ Issuer string `json:"iss,omitempty"`
|
|
|
+ }
|
|
|
+
|
|
|
+ idToken, err := jose.ParseSigned(idTokenString)
|
|
|
+ require.NoError(t, err)
|
|
|
+ err = idToken.UnsafeClaimsWithoutVerification(&claims)
|
|
|
+ require.NoError(t, err)
|
|
|
+
|
|
|
+ // original token contains "Alice Smith" as handle, and name as "wireapp://%40alice_wire@wire.com"
|
|
|
+ assert.Equal(t, "Alice Smith", claims.Handle)
|
|
|
+ assert.Equal(t, "wireapp://%40alice_wire@wire.com", claims.Name)
|
|
|
+ assert.Equal(t, "http://dex:15818/dex", claims.Issuer)
|
|
|
+
|
|
|
+ var m map[string]any
|
|
|
+ err = idToken.UnsafeClaimsWithoutVerification(&m)
|
|
|
+ require.NoError(t, err)
|
|
|
+
|
|
|
+ opts := createWireOptions(t, "") // uses default transformation template
|
|
|
+ result, err := opts.GetOIDCOptions().Transform(m)
|
|
|
+ require.NoError(t, err)
|
|
|
+
|
|
|
+ // default transformation sets preferred username to handle; name as name
|
|
|
+ assert.Equal(t, "Alice Smith", result["handle"].(string))
|
|
|
+ assert.Equal(t, "wireapp://%40alice_wire@wire.com", result["name"].(string))
|
|
|
+ assert.Equal(t, "http://dex:15818/dex", result["iss"].(string))
|
|
|
+
|
|
|
+ // swap the preferred_name and the name
|
|
|
+ swap := `{"name": "{{ .preferred_username }}", "handle": "{{ .name }}"}`
|
|
|
+ opts = createWireOptions(t, swap)
|
|
|
+ result, err = opts.GetOIDCOptions().Transform(m)
|
|
|
+ require.NoError(t, err)
|
|
|
+
|
|
|
+ // with the transformation, handle now contains wireapp://%40alice_wire@wire.com, name contains Alice Smith
|
|
|
+ assert.Equal(t, "wireapp://%40alice_wire@wire.com", result["handle"].(string))
|
|
|
+ assert.Equal(t, "Alice Smith", result["name"].(string))
|
|
|
+ assert.Equal(t, "http://dex:15818/dex", result["iss"].(string))
|
|
|
+}
|