Skip to content

Commit f537cfe

Browse files
committed
Update tests to reference v2
1 parent 030c7f2 commit f537cfe

13 files changed

Lines changed: 1081 additions & 72 deletions

tests.v2/integration/admin_roles_test.go

Lines changed: 454 additions & 0 deletions
Large diffs are not rendered by default.

tests.v2/integration/application_test.go

Lines changed: 129 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,68 @@
1717
package integration
1818

1919
import (
20+
"fmt"
21+
"strings"
2022
"testing"
2123

22-
"github.com/okta/okta-sdk-golang/okta/query"
24+
"github.com/okta/okta-sdk-golang/okta.v2/query"
2325

2426
"github.com/stretchr/testify/assert"
2527
"github.com/stretchr/testify/require"
2628

27-
"github.com/okta/okta-sdk-golang/okta"
29+
"github.com/okta/okta-sdk-golang/okta.v2"
2830

29-
"github.com/okta/okta-sdk-golang/tests"
31+
"github.com/okta/okta-sdk-golang/tests.v2"
3032
)
3133

34+
const myCApem = `-----BEGIN CERTIFICATE-----
35+
MIIDGjCCAgICCQCf0kZljlDWgTANBgkqhkiG9w0BAQsFADBPMQswCQYDVQQGEwJV
36+
UzENMAsGA1UECAwET2hpbzETMBEGA1UEBwwKU3ByaW5nYm9ybzENMAsGA1UECgwE
37+
U2VsZjENMAsGA1UECwwEU2VsZjAeFw0yMDAzMTkxNjI1MzZaFw0yNTAzMTgxNjI1
38+
MzZaME8xCzAJBgNVBAYTAlVTMQ0wCwYDVQQIDARPaGlvMRMwEQYDVQQHDApTcHJp
39+
bmdib3JvMQ0wCwYDVQQKDARTZWxmMQ0wCwYDVQQLDARTZWxmMIIBIjANBgkqhkiG
40+
9w0BAQEFAAOCAQ8AMIIBCgKCAQEA8DC7b9I93e4jZWYZ/601sAYPDg4g+dXZBPv9
41+
qo4N0D19bMx1LsRSk7b8BKCtmJW/Oej70Mh8hTR2Vfkgc6ex/Pmt5pIMnwwpU6Uq
42+
BpjmYOw7jGUxutLSXVsf8tGt+76HquqpIyGwo9aZA4ZdVsC/h4IZFcD/qeeJ7asG
43+
9jyHMv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bfEb0nrWg2S4euP2KrZ2jnEzOgR7RLm3QYuxV+0UQQ4lSoGE6thq
78+
Nd9jmO2rvpK47rjR2Db7p3/E/xfp27x/RMi5KvGF5l6E1xsXXrMCR2M6ghWdqv/C
79+
wjcsLCBxDJreGsTbPeET2Sae6pVvSkKdMJVIwyTMZxyKOukerA9X1g4=
80+
-----END RSA PRIVATE KEY-----`
81+
3282
func Test_can_get_applicaiton_by_id(t *testing.T) {
3383
client, _ := tests.NewClient()
3484

@@ -179,17 +229,15 @@ func Test_list_application_allows_casting_to_correct_type(t *testing.T) {
179229
require.NoError(t, err, "Creating an application should not error")
180230

181231
applist, _, err := client.Application.ListApplications(nil)
232+
require.NoError(t, err, "List applicaitons should not error")
182233

183234
for _, a := range applist {
235+
184236
if a.(*okta.Application).Name == "bookmark" {
185-
if a.(*okta.Application).Id == app2.(okta.BookmarkApplication).Id {
186-
assert.False(t, *a.(*okta.BookmarkApplication).Settings.App.RequestIntegration)
187-
}
188-
}
189-
if a.(*okta.Application).Name == "template_basic_auth" {
190-
if a.(*okta.Application).Id == app1.(okta.BasicAuthApplication).Id {
191-
assert.Equal(t, a.(*okta.BasicAuthApplication).Settings.App.AuthURL,
192-
"https://example.com/auth.html")
237+
if a.(*okta.Application).Id == app2.(*okta.BookmarkApplication).Id {
238+
ba, _, _ := client.Application.GetApplication(a.(*okta.Application).Id, okta.NewBookmarkApplication(), nil)
239+
requestIntegration := ba.(*okta.BookmarkApplication).Settings.App.RequestIntegration
240+
assert.False(t, *requestIntegration)
193241
}
194242
}
195243
}
@@ -298,7 +346,7 @@ func Test_can_add_and_remove_application_users(t *testing.T) {
298346
profile["lastName"] = "Get-User"
299347
profile["email"] = "john-get-user@example.com"
300348
profile["login"] = "john-get-user@example.com"
301-
u := &okta.User{
349+
u := &okta.CreateUserRequest{
302350
Credentials: uc,
303351
Profile: &profile,
304352
}
@@ -402,3 +450,72 @@ func Test_can_set_application_settings_during_update(t *testing.T) {
402450

403451
require.NoError(t, err, "Deleting an application should not error")
404452
}
453+
454+
func Test_can_create_csr_for_application(t *testing.T) {
455+
client, _ := tests.NewClient()
456+
457+
application := create_application(t)
458+
459+
subject := okta.CSRMetadataSubject{
460+
CountryName: "US",
461+
StateOrProvinceName: "California",
462+
LocalityName: "San Francisco",
463+
OrganizationName: "Okta, Inc",
464+
OrganizationalUnitName: "Dev",
465+
CommonName: "SP Issuer",
466+
}
467+
468+
subjectAltNames := okta.CSRMetadataSubjectAltNames{
469+
DnsNames: []string{"dev.okta.com"},
470+
}
471+
472+
csr := okta.CSRMetadata{
473+
Subject: &subject,
474+
SubjectAltNames: &subjectAltNames,
475+
}
476+
477+
csrs, _, err := client.Application.GenerateCsrForApplication(application.Id, csr)
478+
require.NoError(t, err, "Creating an application CSR should not error")
479+
480+
assert.IsType(t, &okta.CSR{}, csrs, "did not return a `okta.CSR` object")
481+
482+
client.Application.DeactivateApplication(application.Id)
483+
_, err = client.Application.DeleteApplication(application.Id)
484+
485+
require.NoError(t, err, "Deleting an application should not error")
486+
}
487+
488+
func create_application(t *testing.T) *okta.BasicAuthApplication {
489+
client, _ := tests.NewClient()
490+
basicApplicationSettingsApplication := okta.NewBasicApplicationSettingsApplication()
491+
basicApplicationSettingsApplication.AuthURL = "https://example.com/auth.html"
492+
basicApplicationSettingsApplication.Url = "https://example.com/auth.html"
493+
494+
basicApplicationSettings := okta.NewBasicApplicationSettings()
495+
basicApplicationSettings.App = basicApplicationSettingsApplication
496+
497+
basicApplication := okta.NewBasicAuthApplication()
498+
basicApplication.Settings = basicApplicationSettings
499+
500+
application, _, err := client.Application.CreateApplication(basicApplication, nil)
501+
require.NoError(t, err, "Creating an application should not error")
502+
503+
return application.(*okta.BasicAuthApplication)
504+
}
505+
506+
func delete_all_apps(t *testing.T) {
507+
client, _ := tests.NewClient()
508+
509+
applicationList, _, err := client.Application.ListApplications(nil)
510+
if err != nil {
511+
fmt.Printf("%+v\n", err)
512+
}
513+
514+
for _, a := range applicationList {
515+
if strings.HasPrefix(a.(*okta.Application).Label, "Template Basic Auth App") ||
516+
strings.HasPrefix(a.(*okta.Application).Label, "Bookmark App") {
517+
client.Application.DeactivateApplication(a.(*okta.Application).Id)
518+
client.Application.DeleteApplication(a.(*okta.Application).Id)
519+
}
520+
}
521+
}
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
/*
2+
* Copyright 2018 - Present Okta, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package integration
18+
19+
import (
20+
"net/http"
21+
"testing"
22+
"time"
23+
24+
"github.com/okta/okta-sdk-golang/okta.v2"
25+
"github.com/okta/okta-sdk-golang/tests.v2"
26+
"github.com/stretchr/testify/assert"
27+
"github.com/stretchr/testify/require"
28+
)
29+
30+
func Test_can_create_an_authorizaiton_server(t *testing.T) {
31+
client, _ := tests.NewClient()
32+
33+
as := okta.AuthorizationServer{
34+
Name: "Sample Authorizaiton Server - Golang",
35+
Description: "Sample Authorizaiton Server Description for Golang",
36+
Audiences: []string{"api://default"},
37+
}
38+
39+
authorizationServer, response, err := client.AuthorizationServer.CreateAuthorizationServer(as)
40+
require.NoError(t, err, "creating an authorizaiton server should not error")
41+
tests.Assert_response(t, response, "POST", "/api/v1/authorizationServers")
42+
43+
assert_authorization_server_model(t, authorizationServer)
44+
45+
_, err = client.AuthorizationServer.DeleteAuthorizationServer(authorizationServer.Id)
46+
}
47+
48+
func Test_can_get_an_authorizaiton_server(t *testing.T) {
49+
client, _ := tests.NewClient()
50+
51+
as := okta.AuthorizationServer{
52+
Name: "Sample Authorizaiton Server - Golang",
53+
Description: "Sample Authorizaiton Server Description for Golang",
54+
Audiences: []string{"api://default"},
55+
}
56+
57+
authorizationServer, response, err := client.AuthorizationServer.CreateAuthorizationServer(as)
58+
require.NoError(t, err, "creating an authorizaiton server should not error")
59+
tests.Assert_response(t, response, "POST", "/api/v1/authorizationServers")
60+
61+
authorizationServer, response, err = client.AuthorizationServer.GetAuthorizationServer(authorizationServer.Id)
62+
require.NoError(t, err, "getting an authorizaiton server should not error")
63+
tests.Assert_response(t, response, "GET", "/api/v1/authorizationServers/"+authorizationServer.Id)
64+
65+
assert_authorization_server_model(t, authorizationServer)
66+
67+
assert.Equal(t, as.Name, authorizationServer.Name, "did not return the same authorization server name")
68+
assert.Equal(t, as.Description, authorizationServer.Description, "did not return the same authorization server description")
69+
70+
_, err = client.AuthorizationServer.DeleteAuthorizationServer(authorizationServer.Id)
71+
}
72+
73+
func Test_can_update_an_authorizaiton_server(t *testing.T) {
74+
client, _ := tests.NewClient()
75+
76+
as := okta.AuthorizationServer{
77+
Name: "Sample Authorizaiton Server - Golang",
78+
Description: "Sample Authorizaiton Server Description for Golang",
79+
Audiences: []string{"api://default"},
80+
}
81+
82+
authorizationServer, response, err := client.AuthorizationServer.CreateAuthorizationServer(as)
83+
require.NoError(t, err, "creating an authorizaiton server should not error")
84+
tests.Assert_response(t, response, "POST", "/api/v1/authorizationServers")
85+
86+
authorizationServer, response, err = client.AuthorizationServer.GetAuthorizationServer(authorizationServer.Id)
87+
require.NoError(t, err, "getting an authorizaiton server should not error")
88+
tests.Assert_response(t, response, "GET", "/api/v1/authorizationServers/"+authorizationServer.Id)
89+
90+
assert_authorization_server_model(t, authorizationServer)
91+
92+
assert.Equal(t, as.Name, authorizationServer.Name, "did not return the same authorization server name")
93+
assert.Equal(t, as.Description, authorizationServer.Description, "did not return the same authorization server description")
94+
95+
updatedName := "Updated Authorization Server - Golang"
96+
updatedDescription := "Updated Authorization Server Description"
97+
authorizationServer.Name = updatedName
98+
authorizationServer.Description = updatedDescription
99+
100+
authorizationServer, response, err = client.AuthorizationServer.UpdateAuthorizationServer(authorizationServer.Id, *authorizationServer)
101+
require.NoError(t, err, "getting an authorizaiton server should not error")
102+
tests.Assert_response(t, response, "PUT", "/api/v1/authorizationServers/"+authorizationServer.Id)
103+
104+
assert_authorization_server_model(t, authorizationServer)
105+
106+
assert.Equal(t, updatedName, authorizationServer.Name, "did not return the same authorization server name")
107+
assert.Equal(t, updatedDescription, authorizationServer.Description, "did not return the same authorization server description")
108+
109+
_, err = client.AuthorizationServer.DeleteAuthorizationServer(authorizationServer.Id)
110+
}
111+
112+
func Test_can_delete_an_authorizaiton_server(t *testing.T) {
113+
client, _ := tests.NewClient()
114+
115+
as := okta.AuthorizationServer{
116+
Name: "Sample Authorizaiton Server - Golang",
117+
Description: "Sample Authorizaiton Server Description for Golang",
118+
Audiences: []string{"api://default"},
119+
}
120+
121+
authorizationServer, response, err := client.AuthorizationServer.CreateAuthorizationServer(as)
122+
require.NoError(t, err, "creating an authorizaiton server should not error")
123+
tests.Assert_response(t, response, "POST", "/api/v1/authorizationServers")
124+
125+
authorizationServer, response, err = client.AuthorizationServer.GetAuthorizationServer(authorizationServer.Id)
126+
require.NoError(t, err, "getting an authorizaiton server should not error")
127+
tests.Assert_response(t, response, "GET", "/api/v1/authorizationServers/"+authorizationServer.Id)
128+
129+
assert_authorization_server_model(t, authorizationServer)
130+
131+
assert.Equal(t, as.Name, authorizationServer.Name, "did not return the same authorization server name")
132+
assert.Equal(t, as.Description, authorizationServer.Description, "did not return the same authorization server description")
133+
134+
response, err = client.AuthorizationServer.DeleteAuthorizationServer(authorizationServer.Id)
135+
assert.Equal(t, http.StatusNoContent, response.StatusCode, "did not return a 204 status code during delete")
136+
137+
authorizationServer, response, err = client.AuthorizationServer.GetAuthorizationServer(authorizationServer.Id)
138+
assert.Error(t, err, "Finding an authorization server by id should have reported an error")
139+
assert.Equal(t, http.StatusNotFound, response.StatusCode, "Should have resulted in a 404 when finding a deleted authorization server")
140+
}
141+
142+
func Test_can_list_authorizaiton_servers(t *testing.T) {
143+
client, _ := tests.NewClient()
144+
145+
as := okta.AuthorizationServer{
146+
Name: "Sample Authorizaiton Server - Golang",
147+
Description: "Sample Authorizaiton Server Description for Golang",
148+
Audiences: []string{"api://default"},
149+
}
150+
151+
authorizationServer, response, err := client.AuthorizationServer.CreateAuthorizationServer(as)
152+
require.NoError(t, err, "creating an authorizaiton server should not error")
153+
tests.Assert_response(t, response, "POST", "/api/v1/authorizationServers")
154+
155+
authorizationServerList, response, err := client.AuthorizationServer.ListAuthorizationServers(nil)
156+
require.NoError(t, err, "list authorizaiton servers should not error")
157+
tests.Assert_response(t, response, "GET", "/api/v1/authorizationServers")
158+
159+
found := false
160+
for _, authServer := range authorizationServerList {
161+
if authServer.Id == authorizationServer.Id {
162+
assert_authorization_server_model(t, authServer)
163+
found = true
164+
}
165+
}
166+
assert.True(t, found, "Could not find authorization from list")
167+
168+
_, err = client.AuthorizationServer.DeleteAuthorizationServer(authorizationServer.Id)
169+
}
170+
171+
func Test_can_activate_an_authorizaiton_server(t *testing.T) {
172+
client, _ := tests.NewClient()
173+
174+
as := okta.AuthorizationServer{
175+
Name: "Sample Authorizaiton Server - Golang",
176+
Description: "Sample Authorizaiton Server Description for Golang",
177+
Audiences: []string{"api://default"},
178+
}
179+
180+
authorizationServer, response, err := client.AuthorizationServer.CreateAuthorizationServer(as)
181+
require.NoError(t, err, "creating an authorizaiton server should not error")
182+
tests.Assert_response(t, response, "POST", "/api/v1/authorizationServers")
183+
assert.Equal(t, "ACTIVE", authorizationServer.Status, "should have active status after creating")
184+
185+
response, err = client.AuthorizationServer.DeactivateAuthorizationServer(authorizationServer.Id)
186+
require.NoError(t, err, "deactivating an authorizaiton server should not error")
187+
tests.Assert_response(t, response, "POST", "/api/v1/authorizationServers/"+authorizationServer.Id+"/lifecycle/deactivate")
188+
189+
authorizationServer, _, _ = client.AuthorizationServer.GetAuthorizationServer(authorizationServer.Id)
190+
assert.Equal(t, "INACTIVE", authorizationServer.Status, "should have inactive status after deactivating")
191+
192+
response, err = client.AuthorizationServer.ActivateAuthorizationServer(authorizationServer.Id)
193+
require.NoError(t, err, "activating an authorizaiton server should not error")
194+
tests.Assert_response(t, response, "POST", "/api/v1/authorizationServers/"+authorizationServer.Id+"/lifecycle/activate")
195+
196+
// authorizationServer, response, _ = client.AuthorizationServer.GetAuthorizationServer(authorizationServer.Id)
197+
// assert.Equal(t, "ACTIVE", authorizationServer.Status, "should have active status after activating")
198+
199+
_, err = client.AuthorizationServer.DeleteAuthorizationServer(authorizationServer.Id)
200+
}
201+
202+
func assert_authorization_server_model(t *testing.T, authorizationServer *okta.AuthorizationServer) {
203+
require.IsType(t, &okta.AuthorizationServer{}, authorizationServer, "did not return `*okta.AuthorizationServer` type as first variable")
204+
assert.NotEmpty(t, authorizationServer.Id, "id should not be empty")
205+
assert.NotEmpty(t, authorizationServer.Audiences, "audiences should not be empty")
206+
assert.NotEmpty(t, authorizationServer.Created, "created should not be empty")
207+
assert.IsType(t, &time.Time{}, authorizationServer.Created, "created should not be of type `*time.Time`")
208+
assert.NotEmpty(t, authorizationServer.Credentials, "credentials should not be empty")
209+
assert.IsType(t, &okta.AuthorizationServerCredentials{}, authorizationServer.Credentials, "credentials should not be of type `*okta.AuthorizationServerCredentials`")
210+
assert.NotEmpty(t, authorizationServer.Description, "description should not be empty")
211+
assert.NotEmpty(t, authorizationServer.Issuer, "issuer should not be empty")
212+
assert.NotEmpty(t, authorizationServer.IssuerMode, "issuerMode should not be empty")
213+
assert.NotEmpty(t, authorizationServer.LastUpdated, "lastUpdated should not be empty")
214+
assert.IsType(t, &time.Time{}, authorizationServer.LastUpdated, "lastUpdated should not be of type `*time.Time`")
215+
assert.NotEmpty(t, authorizationServer.Name, "name should not be empty")
216+
assert.NotEmpty(t, authorizationServer.Status, "status should not be empty")
217+
}

0 commit comments

Comments
 (0)