@@ -26,6 +26,7 @@ import (
26
26
27
27
func TestPackageContainer (t * testing.T ) {
28
28
defer prepareTestEnv (t )()
29
+
29
30
user := unittest .AssertExistsAndLoadBean (t , & user_model.User {ID : 2 }).(* user_model.User )
30
31
31
32
has := func (l packages_model.PackagePropertyList , name string ) bool {
@@ -36,6 +37,15 @@ func TestPackageContainer(t *testing.T) {
36
37
}
37
38
return false
38
39
}
40
+ getAllByName := func (l packages_model.PackagePropertyList , name string ) []string {
41
+ values := make ([]string , 0 , len (l ))
42
+ for _ , pp := range l {
43
+ if pp .Name == name {
44
+ values = append (values , pp .Value )
45
+ }
46
+ }
47
+ return values
48
+ }
39
49
40
50
images := []string {"test" , "te/st" }
41
51
tags := []string {"latest" , "main" }
@@ -66,7 +76,7 @@ func TestPackageContainer(t *testing.T) {
66
76
Token string `json:"token"`
67
77
}
68
78
69
- authenticate := []string {`Bearer realm="` + setting .AppURL + `v2/token"` }
79
+ authenticate := []string {`Bearer realm="` + setting .AppURL + `v2/token",service="container_registry",scope="*" ` }
70
80
71
81
t .Run ("Anonymous" , func (t * testing.T ) {
72
82
defer PrintCurrentTest (t )()
@@ -236,7 +246,8 @@ func TestPackageContainer(t *testing.T) {
236
246
assert .Nil (t , pd .SemVer )
237
247
assert .Equal (t , image , pd .Package .Name )
238
248
assert .Equal (t , tag , pd .Version .Version )
239
- assert .True (t , has (pd .Properties , container_module .PropertyManifestTagged ))
249
+ assert .ElementsMatch (t , []string {strings .ToLower (user .LowerName + "/" + image )}, getAllByName (pd .PackageProperties , container_module .PropertyRepository ))
250
+ assert .True (t , has (pd .VersionProperties , container_module .PropertyManifestTagged ))
240
251
241
252
assert .IsType (t , & container_module.Metadata {}, pd .Metadata )
242
253
metadata := pd .Metadata .(* container_module.Metadata )
@@ -330,7 +341,8 @@ func TestPackageContainer(t *testing.T) {
330
341
assert .Nil (t , pd .SemVer )
331
342
assert .Equal (t , image , pd .Package .Name )
332
343
assert .Equal (t , untaggedManifestDigest , pd .Version .Version )
333
- assert .False (t , has (pd .Properties , container_module .PropertyManifestTagged ))
344
+ assert .ElementsMatch (t , []string {strings .ToLower (user .LowerName + "/" + image )}, getAllByName (pd .PackageProperties , container_module .PropertyRepository ))
345
+ assert .False (t , has (pd .VersionProperties , container_module .PropertyManifestTagged ))
334
346
335
347
assert .IsType (t , & container_module.Metadata {}, pd .Metadata )
336
348
@@ -362,18 +374,10 @@ func TestPackageContainer(t *testing.T) {
362
374
assert .Nil (t , pd .SemVer )
363
375
assert .Equal (t , image , pd .Package .Name )
364
376
assert .Equal (t , multiTag , pd .Version .Version )
365
- assert .True (t , has (pd .Properties , container_module .PropertyManifestTagged ))
377
+ assert .ElementsMatch (t , []string {strings .ToLower (user .LowerName + "/" + image )}, getAllByName (pd .PackageProperties , container_module .PropertyRepository ))
378
+ assert .True (t , has (pd .VersionProperties , container_module .PropertyManifestTagged ))
366
379
367
- getAllByName := func (l packages_model.PackagePropertyList , name string ) []string {
368
- values := make ([]string , 0 , len (l ))
369
- for _ , pp := range l {
370
- if pp .Name == name {
371
- values = append (values , pp .Value )
372
- }
373
- }
374
- return values
375
- }
376
- assert .ElementsMatch (t , []string {manifestDigest , untaggedManifestDigest }, getAllByName (pd .Properties , container_module .PropertyManifestReference ))
380
+ assert .ElementsMatch (t , []string {manifestDigest , untaggedManifestDigest }, getAllByName (pd .VersionProperties , container_module .PropertyManifestReference ))
377
381
378
382
assert .IsType (t , & container_module.Metadata {}, pd .Metadata )
379
383
metadata := pd .Metadata .(* container_module.Metadata )
@@ -528,4 +532,56 @@ func TestPackageContainer(t *testing.T) {
528
532
})
529
533
})
530
534
}
535
+
536
+ t .Run ("OwnerNameChange" , func (t * testing.T ) {
537
+ defer PrintCurrentTest (t )()
538
+
539
+ checkCatalog := func (owner string ) func (t * testing.T ) {
540
+ return func (t * testing.T ) {
541
+ defer PrintCurrentTest (t )()
542
+
543
+ req := NewRequest (t , "GET" , fmt .Sprintf ("%sv2/_catalog" , setting .AppURL ))
544
+ addTokenAuthHeader (req , userToken )
545
+ resp := MakeRequest (t , req , http .StatusOK )
546
+
547
+ type RepositoryList struct {
548
+ Repositories []string `json:"repositories"`
549
+ }
550
+
551
+ repoList := & RepositoryList {}
552
+ DecodeJSON (t , resp , & repoList )
553
+
554
+ assert .Len (t , repoList .Repositories , len (images ))
555
+ names := make ([]string , 0 , len (images ))
556
+ for _ , image := range images {
557
+ names = append (names , strings .ToLower (owner + "/" + image ))
558
+ }
559
+ assert .ElementsMatch (t , names , repoList .Repositories )
560
+ }
561
+ }
562
+
563
+ t .Run (fmt .Sprintf ("Catalog[%s]" , user .LowerName ), checkCatalog (user .LowerName ))
564
+
565
+ session := loginUser (t , user .Name )
566
+
567
+ newOwnerName := "newUsername"
568
+
569
+ req := NewRequestWithValues (t , "POST" , "/user/settings" , map [string ]string {
570
+ "_csrf" : GetCSRF (t , session , "/user/settings" ),
571
+ "name" : newOwnerName ,
572
+
573
+ "language" : "en-US" ,
574
+ })
575
+ session .MakeRequest (t , req , http .StatusSeeOther )
576
+
577
+ t .Run (fmt .Sprintf ("Catalog[%s]" , newOwnerName ), checkCatalog (newOwnerName ))
578
+
579
+ req = NewRequestWithValues (t , "POST" , "/user/settings" , map [string ]string {
580
+ "_csrf" : GetCSRF (t , session , "/user/settings" ),
581
+ "name" : user .Name ,
582
+
583
+ "language" : "en-US" ,
584
+ })
585
+ session .MakeRequest (t , req , http .StatusSeeOther )
586
+ })
531
587
}
0 commit comments