@@ -27,8 +27,16 @@ import (
27
27
"google.golang.org/api/iterator"
28
28
)
29
29
30
+ const oidcConfigResponse = `{
31
+ "name":"projects/mock-project-id/oauthIdpConfigs/oidc.provider",
32
+ "clientId": "CLIENT_ID",
33
+ "issuer": "https://oidc.com/issuer",
34
+ "displayName": "oidcProviderName",
35
+ "enabled": true
36
+ }`
37
+
30
38
const samlConfigResponse = `{
31
- "name":"projects/mock-project-id/inboundSamlConfigs/saml.provider",
39
+ "name": "projects/mock-project-id/inboundSamlConfigs/saml.provider",
32
40
"idpConfig": {
33
41
"idpEntityId": "IDP_ENTITY_ID",
34
42
"ssoUrl": "https://example.com/login",
@@ -57,6 +65,14 @@ var idpCertsMap = []interface{}{
57
65
map [string ]interface {}{"x509Certificate" : "CERT2" },
58
66
}
59
67
68
+ var oidcProviderConfig = & OIDCProviderConfig {
69
+ ID : "oidc.provider" ,
70
+ DisplayName : "oidcProviderName" ,
71
+ Enabled : true ,
72
+ ClientID : "CLIENT_ID" ,
73
+ Issuer : "https://oidc.com/issuer" ,
74
+ }
75
+
60
76
var samlProviderConfig = & SAMLProviderConfig {
61
77
ID : "saml.provider" ,
62
78
DisplayName : "samlProviderName" ,
@@ -69,12 +85,111 @@ var samlProviderConfig = &SAMLProviderConfig{
69
85
CallbackURL : "https://projectId.firebaseapp.com/__/auth/handler" ,
70
86
}
71
87
88
+ var invalidOIDCConfigIDs = []string {
89
+ "" ,
90
+ "invalid.id" ,
91
+ "saml.config" ,
92
+ }
93
+
72
94
var invalidSAMLConfigIDs = []string {
73
95
"" ,
74
96
"invalid.id" ,
75
97
"oidc.config" ,
76
98
}
77
99
100
+ func TestOIDCProviderConfig (t * testing.T ) {
101
+ s := echoServer ([]byte (oidcConfigResponse ), t )
102
+ defer s .Close ()
103
+
104
+ client := s .Client .pcc
105
+ oidc , err := client .OIDCProviderConfig (context .Background (), "oidc.provider" )
106
+ if err != nil {
107
+ t .Fatal (err )
108
+ }
109
+
110
+ if ! reflect .DeepEqual (oidc , oidcProviderConfig ) {
111
+ t .Errorf ("OIDCProviderConfig() = %#v; want = %#v" , oidc , oidcProviderConfig )
112
+ }
113
+
114
+ req := s .Req [0 ]
115
+ if req .Method != http .MethodGet {
116
+ t .Errorf ("OIDCProviderConfig() Method = %q; want = %q" , req .Method , http .MethodGet )
117
+ }
118
+
119
+ wantURL := "/projects/mock-project-id/oauthIdpConfigs/oidc.provider"
120
+ if req .URL .Path != wantURL {
121
+ t .Errorf ("OIDCProviderConfig() URL = %q; want = %q" , req .URL .Path , wantURL )
122
+ }
123
+ }
124
+
125
+ func TestOIDCProviderConfigInvalidID (t * testing.T ) {
126
+ client := & providerConfigClient {}
127
+ wantErr := "invalid OIDC provider id: "
128
+
129
+ for _ , id := range invalidOIDCConfigIDs {
130
+ saml , err := client .OIDCProviderConfig (context .Background (), id )
131
+ if saml != nil || err == nil || ! strings .HasPrefix (err .Error (), wantErr ) {
132
+ t .Errorf ("OIDCProviderConfig(%q) = (%v, %v); want = (nil, %q)" , id , saml , err , wantErr )
133
+ }
134
+ }
135
+ }
136
+
137
+ func TestOIDCProviderConfigError (t * testing.T ) {
138
+ s := echoServer ([]byte (notFoundResponse ), t )
139
+ defer s .Close ()
140
+ s .Status = http .StatusNotFound
141
+
142
+ client := s .Client .pcc
143
+ saml , err := client .OIDCProviderConfig (context .Background (), "oidc.provider" )
144
+ if saml != nil || err == nil || ! IsConfigurationNotFound (err ) {
145
+ t .Errorf ("OIDCProviderConfig() = (%v, %v); want = (nil, ConfigurationNotFound)" , saml , err )
146
+ }
147
+ }
148
+
149
+ func TestDeleteOIDCProviderConfig (t * testing.T ) {
150
+ s := echoServer ([]byte ("{}" ), t )
151
+ defer s .Close ()
152
+
153
+ client := s .Client .pcc
154
+ if err := client .DeleteOIDCProviderConfig (context .Background (), "oidc.provider" ); err != nil {
155
+ t .Fatal (err )
156
+ }
157
+
158
+ req := s .Req [0 ]
159
+ if req .Method != http .MethodDelete {
160
+ t .Errorf ("DeleteOIDCProviderConfig() Method = %q; want = %q" , req .Method , http .MethodDelete )
161
+ }
162
+
163
+ wantURL := "/projects/mock-project-id/oauthIdpConfigs/oidc.provider"
164
+ if req .URL .Path != wantURL {
165
+ t .Errorf ("DeleteOIDCProviderConfig() URL = %q; want = %q" , req .URL .Path , wantURL )
166
+ }
167
+ }
168
+
169
+ func TestDeleteOIDCProviderConfigInvalidID (t * testing.T ) {
170
+ client := & providerConfigClient {}
171
+ wantErr := "invalid OIDC provider id: "
172
+
173
+ for _ , id := range invalidOIDCConfigIDs {
174
+ err := client .DeleteOIDCProviderConfig (context .Background (), id )
175
+ if err == nil || ! strings .HasPrefix (err .Error (), wantErr ) {
176
+ t .Errorf ("DeleteOIDCProviderConfig(%q) = %v; want = %q" , id , err , wantErr )
177
+ }
178
+ }
179
+ }
180
+
181
+ func TestDeleteOIDCProviderConfigError (t * testing.T ) {
182
+ s := echoServer ([]byte (notFoundResponse ), t )
183
+ defer s .Close ()
184
+ s .Status = http .StatusNotFound
185
+
186
+ client := s .Client .pcc
187
+ err := client .DeleteOIDCProviderConfig (context .Background (), "oidc.provider" )
188
+ if err == nil || ! IsConfigurationNotFound (err ) {
189
+ t .Errorf ("DeleteOIDCProviderConfig() = %v; want = ConfigurationNotFound" , err )
190
+ }
191
+ }
192
+
78
193
func TestSAMLProviderConfig (t * testing.T ) {
79
194
s := echoServer ([]byte (samlConfigResponse ), t )
80
195
defer s .Close ()
0 commit comments