@@ -154,6 +154,145 @@ func TestPrivateRegistriesService_CreateOrganizationPrivateRegistry(t *testing.T
154154 })
155155}
156156
157+ func TestPrivateRegistriesService_CreateOrganizationPrivateRegistry_OIDC (t * testing.T ) {
158+ t .Parallel ()
159+ client , mux , _ := setup (t )
160+
161+ input := & CreateOrganizationPrivateRegistry {
162+ RegistryType : "maven_repository" ,
163+ URL : "https://maven.pkg.github.com/OWNER/REPOSITORY" ,
164+ AuthType : Ptr ("oidc_azure" ),
165+ TenantID : Ptr ("my-tenant-id" ),
166+ ClientID : Ptr ("my-client-id" ),
167+ ReplacesBase : Ptr (true ),
168+ Visibility : PrivateRegistryVisibilitySelected ,
169+ SelectedRepositoryIDs : []int64 {1 , 2 , 3 },
170+ }
171+
172+ mux .HandleFunc ("/orgs/o/private-registries" , func (w http.ResponseWriter , r * http.Request ) {
173+ var v * CreateOrganizationPrivateRegistry
174+ assertNilError (t , json .NewDecoder (r .Body ).Decode (& v ))
175+
176+ testMethod (t , r , "POST" )
177+ if ! cmp .Equal (v , input ) {
178+ t .Errorf ("Request body = %+v, want %+v" , v , input )
179+ }
180+
181+ w .WriteHeader (http .StatusCreated )
182+ fmt .Fprint (w , `{
183+ "name": "MAVEN_REPOSITORY_SECRET",
184+ "registry_type": "maven_repository",
185+ "visibility": "selected",
186+ "selected_repository_ids": [1, 2, 3],
187+ "created_at": "2019-08-10T14:59:22Z",
188+ "updated_at": "2020-01-10T14:59:22Z"
189+ }` )
190+ })
191+
192+ ctx := t .Context ()
193+ privateRegistry , _ , err := client .PrivateRegistries .CreateOrganizationPrivateRegistry (ctx , "o" , * input )
194+ if err != nil {
195+ t .Fatalf ("PrivateRegistries.CreateOrganizationPrivateRegistry (OIDC) returned error: %v" , err )
196+ }
197+
198+ want := & PrivateRegistry {
199+ Name : Ptr ("MAVEN_REPOSITORY_SECRET" ),
200+ RegistryType : Ptr ("maven_repository" ),
201+ CreatedAt : & Timestamp {time .Date (2019 , time .August , 10 , 14 , 59 , 22 , 0 , time .UTC )},
202+ UpdatedAt : & Timestamp {time .Date (2020 , time .January , 10 , 14 , 59 , 22 , 0 , time .UTC )},
203+ Visibility : Ptr (PrivateRegistryVisibilitySelected ),
204+ SelectedRepositoryIDs : []int64 {1 , 2 , 3 },
205+ }
206+ if diff := cmp .Diff (want , privateRegistry ); diff != "" {
207+ t .Errorf ("PrivateRegistries.CreateOrganizationPrivateRegistry (OIDC) mismatch (-want +got):\\ n%v" , diff )
208+ }
209+ }
210+
211+ func TestPrivateRegistries_UpdateOrganizationPrivateRegistry_OIDC (t * testing.T ) {
212+ t .Parallel ()
213+ client , mux , _ := setup (t )
214+
215+ input := & UpdateOrganizationPrivateRegistry {
216+ AuthType : Ptr ("oidc_aws" ),
217+ AwsRegion : Ptr ("us-east-1" ),
218+ AccountID : Ptr ("123456789012" ),
219+ RoleName : Ptr ("my-role" ),
220+ Domain : Ptr ("my-domain" ),
221+ DomainOwner : Ptr ("123456789012" ),
222+ Audience : Ptr ("sts.amazonaws.com" ),
223+ Visibility : Ptr (PrivateRegistryVisibilitySelected ),
224+ }
225+
226+ mux .HandleFunc ("/orgs/o/private-registries/AWS_REGISTRY_SECRET" , func (w http.ResponseWriter , r * http.Request ) {
227+ var v * UpdateOrganizationPrivateRegistry
228+ assertNilError (t , json .NewDecoder (r .Body ).Decode (& v ))
229+
230+ testMethod (t , r , "PATCH" )
231+ if ! cmp .Equal (v , input ) {
232+ t .Errorf ("Request body = %+v, want %+v" , v , input )
233+ }
234+
235+ w .WriteHeader (http .StatusNoContent )
236+ })
237+
238+ ctx := t .Context ()
239+ _ , err := client .PrivateRegistries .UpdateOrganizationPrivateRegistry (ctx , "o" , "AWS_REGISTRY_SECRET" , * input )
240+ if err != nil {
241+ t .Fatalf ("PrivateRegistries.UpdateOrganizationPrivateRegistry (OIDC) returned error: %v" , err )
242+ }
243+ }
244+
245+ func TestPrivateRegistriesService_CreateOrganizationPrivateRegistry_OIDCJFrog (t * testing.T ) {
246+ t .Parallel ()
247+ client , mux , _ := setup (t )
248+
249+ input := & CreateOrganizationPrivateRegistry {
250+ RegistryType : "npm_registry" ,
251+ URL : "https://my.jfrog.io/artifactory/api/npm/npm-remote" ,
252+ AuthType : Ptr ("oidc_jfrog" ),
253+ JfrogOidcProviderName : Ptr ("my-jfrog-provider" ),
254+ Audience : Ptr ("jfrog" ),
255+ IdentityMappingName : Ptr ("my-identity-mapping" ),
256+ Visibility : PrivateRegistryVisibilityPrivate ,
257+ }
258+
259+ mux .HandleFunc ("/orgs/o/private-registries" , func (w http.ResponseWriter , r * http.Request ) {
260+ var v * CreateOrganizationPrivateRegistry
261+ assertNilError (t , json .NewDecoder (r .Body ).Decode (& v ))
262+
263+ testMethod (t , r , "POST" )
264+ if ! cmp .Equal (v , input ) {
265+ t .Errorf ("Request body = %+v, want %+v" , v , input )
266+ }
267+
268+ w .WriteHeader (http .StatusCreated )
269+ fmt .Fprint (w , `{
270+ "name": "NPM_REGISTRY_SECRET",
271+ "registry_type": "npm_registry",
272+ "visibility": "private",
273+ "created_at": "2019-08-10T14:59:22Z",
274+ "updated_at": "2020-01-10T14:59:22Z"
275+ }` )
276+ })
277+
278+ ctx := t .Context ()
279+ privateRegistry , _ , err := client .PrivateRegistries .CreateOrganizationPrivateRegistry (ctx , "o" , * input )
280+ if err != nil {
281+ t .Fatalf ("PrivateRegistries.CreateOrganizationPrivateRegistry (OIDC JFrog) returned error: %v" , err )
282+ }
283+
284+ want := & PrivateRegistry {
285+ Name : Ptr ("NPM_REGISTRY_SECRET" ),
286+ RegistryType : Ptr ("npm_registry" ),
287+ CreatedAt : & Timestamp {time .Date (2019 , time .August , 10 , 14 , 59 , 22 , 0 , time .UTC )},
288+ UpdatedAt : & Timestamp {time .Date (2020 , time .January , 10 , 14 , 59 , 22 , 0 , time .UTC )},
289+ Visibility : Ptr (PrivateRegistryVisibilityPrivate ),
290+ }
291+ if diff := cmp .Diff (want , privateRegistry ); diff != "" {
292+ t .Errorf ("PrivateRegistries.CreateOrganizationPrivateRegistry (OIDC JFrog) mismatch (-want +got):\\ n%v" , diff )
293+ }
294+ }
295+
157296func TestPrivateRegistriesService_GetOrganizationPrivateRegistriesPublicKey (t * testing.T ) {
158297 t .Parallel ()
159298 client , mux , _ := setup (t )
0 commit comments