1
16
17 package integration
18
19 import (
20 "context"
21 "encoding/json"
22 "testing"
23
24 "github.com/okta/okta-sdk-golang/v2/okta"
25 "github.com/okta/okta-sdk-golang/v2/tests"
26
27 "github.com/stretchr/testify/assert"
28 "github.com/stretchr/testify/require"
29 )
30
31 func TestCreateIdentityProvider(t *testing.T) {
32 ctx, client, err := tests.NewClient(context.TODO())
33 require.NoError(t, err)
34
35 idpName := testName("Test Identity Provider")
36 testIdp, err := createIdentityProvider(idpName)
37 require.NoError(t, err)
38
39 resultIpd, response, err := client.IdentityProvider.CreateIdentityProvider(ctx, *testIdp)
40 go cleanupTestIdentityProvider(ctx, client, resultIpd)
41
42 require.NoError(t, err, "creating an identity provider hook should not error")
43 tests.AssertResponse(t, response, "POST", "/api/v1/idps")
44 assert.Equal(t, idpName, resultIpd.Name)
45 }
46
47 func cleanupTestIdentityProvider(ctx context.Context, client *okta.Client, idp *okta.IdentityProvider) {
48 if idp == nil || idp.Name == "" {
49 return
50 }
51 _, _ = client.IdentityProvider.DeleteIdentityProvider(ctx, idp.Id)
52 }
53
54 func createIdentityProvider(name string) (*okta.IdentityProvider, error) {
55 jsonIDP := `
56 {
57 "type": "OIDC",
58 "name": "` + name + `",
59 "protocol": {
60 "algorithms": {
61 "request": {
62 "signature": {
63 "algorithm": "SHA-256",
64 "scope": "REQUEST"
65 }
66 },
67 "response": {
68 "signature": {
69 "algorithm": "SHA-256",
70 "scope": "ANY"
71 }
72 }
73 },
74 "endpoints": {
75 "acs": {
76 "binding": "HTTP-POST",
77 "type": "INSTANCE"
78 },
79 "authorization": {
80 "binding": "HTTP-REDIRECT",
81 "url": "https://idp.example.com/authorize"
82 },
83 "token": {
84 "binding": "HTTP-POST",
85 "url": "https://idp.example.com/token"
86 },
87 "userInfo": {
88 "binding": "HTTP-REDIRECT",
89 "url": "https://idp.example.com/userinfo"
90 },
91 "jwks": {
92 "binding": "HTTP-REDIRECT",
93 "url": "https://idp.example.com/keys"
94 }
95 },
96 "scopes": [
97 "openid",
98 "profile",
99 "email"
100 ],
101 "type": "OIDC",
102 "credentials": {
103 "client": {
104 "client_id": "your-client-id",
105 "client_secret": "your-client-secret"
106 }
107 },
108 "issuer": {
109 "url": "https://idp.example.com"
110 }
111 },
112 "policy": {
113 "accountLink": {
114 "action": "AUTO",
115 "filter": null
116 },
117 "provisioning": {
118 "action": "AUTO",
119 "conditions": {
120 "deprovisioned": {
121 "action": "NONE"
122 },
123 "suspended": {
124 "action": "NONE"
125 }
126 },
127 "groups": {
128 "action": "NONE"
129 }
130 },
131 "maxClockSkew": 120000,
132 "subject": {
133 "userNameTemplate": {
134 "template": "idpuser.email"
135 },
136 "matchType": "USERNAME"
137 }
138 }
139 }
140 `
141
142 var idp okta.IdentityProvider
143
144 err := json.Unmarshal([]byte(jsonIDP), &idp)
145 if err != nil {
146 return nil, err
147 }
148
149 return &idp, nil
150 }
151
View as plain text