72
72
-----END OPENSSH PRIVATE KEY-----`
73
73
)
74
74
75
+ var emptyRemoteOpts []remote.Option
76
+
75
77
func TestLogs (t * testing.T ) {
76
78
t .Parallel ()
77
79
@@ -494,7 +496,7 @@ func TestBuildFromDevcontainerWithFeatures(t *testing.T) {
494
496
t .Parallel ()
495
497
496
498
registry := registrytest .New (t )
497
- feature1Ref := registrytest .WriteContainer (t , registry , "coder/test1:latest" , features .TarLayerMediaType , map [string ]any {
499
+ feature1Ref := registrytest .WriteContainer (t , registry , emptyRemoteOpts , "coder/test1:latest" , features .TarLayerMediaType , map [string ]any {
498
500
"devcontainer-feature.json" : & features.Spec {
499
501
ID : "test1" ,
500
502
Name : "test1" ,
@@ -508,7 +510,7 @@ func TestBuildFromDevcontainerWithFeatures(t *testing.T) {
508
510
"install.sh" : "echo $BANANAS > /test1output" ,
509
511
})
510
512
511
- feature2Ref := registrytest .WriteContainer (t , registry , "coder/test2:latest" , features .TarLayerMediaType , map [string ]any {
513
+ feature2Ref := registrytest .WriteContainer (t , registry , emptyRemoteOpts , "coder/test2:latest" , features .TarLayerMediaType , map [string ]any {
512
514
"devcontainer-feature.json" : & features.Spec {
513
515
ID : "test2" ,
514
516
Name : "test2" ,
@@ -574,6 +576,90 @@ func TestBuildFromDevcontainerWithFeatures(t *testing.T) {
574
576
require .Equal (t , "hello from test 3!" , strings .TrimSpace (test3Output ))
575
577
}
576
578
579
+ func TestBuildFromDevcontainerWithFeaturesInAuthRepo (t * testing.T ) {
580
+ t .Parallel ()
581
+
582
+ // Given: an empty registry with auth enabled
583
+ authOpts := setupInMemoryRegistryOpts {
584
+ Username : "testing" ,
585
+ Password : "testing" ,
586
+ }
587
+ remoteAuthOpt := append (emptyRemoteOpts , remote .WithAuth (& authn.Basic {Username : authOpts .Username , Password : authOpts .Password }))
588
+ testReg := setupInMemoryRegistry (t , authOpts )
589
+ regAuthJSON , err := json .Marshal (envbuilder.DockerConfig {
590
+ AuthConfigs : map [string ]clitypes.AuthConfig {
591
+ testReg : {
592
+ Username : authOpts .Username ,
593
+ Password : authOpts .Password ,
594
+ },
595
+ },
596
+ })
597
+ require .NoError (t , err )
598
+
599
+ // push a feature to the registry
600
+ featureRef := registrytest .WriteContainer (t , testReg , remoteAuthOpt , "features/test-feature:latest" , features .TarLayerMediaType , map [string ]any {
601
+ "devcontainer-feature.json" : & features.Spec {
602
+ ID : "test1" ,
603
+ Name : "test1" ,
604
+ Version : "1.0.0" ,
605
+ Options : map [string ]features.Option {
606
+ "bananas" : {
607
+ Type : "string" ,
608
+ },
609
+ },
610
+ },
611
+ "install.sh" : "echo $BANANAS > /test1output" ,
612
+ })
613
+
614
+ // Create a git repo with a devcontainer.json that uses the feature
615
+ srv := gittest .CreateGitServer (t , gittest.Options {
616
+ Files : map [string ]string {
617
+ ".devcontainer/devcontainer.json" : `{
618
+ "name": "Test",
619
+ "build": {
620
+ "dockerfile": "Dockerfile"
621
+ },
622
+ "features": {
623
+ "` + featureRef + `": {
624
+ "bananas": "hello from test 1!"
625
+ }
626
+ }
627
+ }` ,
628
+ ".devcontainer/Dockerfile" : "FROM " + testImageUbuntu ,
629
+ },
630
+ })
631
+ opts := []string {
632
+ envbuilderEnv ("GIT_URL" , srv .URL ),
633
+ }
634
+
635
+ // Test that things fail when no auth is provided
636
+ t .Run ("NoAuth" , func (t * testing.T ) {
637
+ t .Parallel ()
638
+
639
+ // run the envbuilder with the auth config
640
+ _ , err := runEnvbuilder (t , runOpts {env : opts })
641
+ require .ErrorContains (t , err , "Unauthorized" )
642
+ })
643
+
644
+ // test that things work when auth is provided
645
+ t .Run ("WithAuth" , func (t * testing.T ) {
646
+ t .Parallel ()
647
+
648
+ optsWithAuth := append (
649
+ opts ,
650
+ envbuilderEnv ("DOCKER_CONFIG_BASE64" , base64 .StdEncoding .EncodeToString (regAuthJSON )),
651
+ )
652
+
653
+ // run the envbuilder with the auth config
654
+ ctr , err := runEnvbuilder (t , runOpts {env : optsWithAuth })
655
+ require .NoError (t , err )
656
+
657
+ // check that the feature was installed correctly
658
+ testOutput := execContainer (t , ctr , "cat /test1output" )
659
+ require .Equal (t , "hello from test 1!" , strings .TrimSpace (testOutput ))
660
+ })
661
+ }
662
+
577
663
func TestBuildFromDockerfileAndConfig (t * testing.T ) {
578
664
t .Parallel ()
579
665
@@ -1545,7 +1631,7 @@ func TestPushImage(t *testing.T) {
1545
1631
t .Parallel ()
1546
1632
1547
1633
// Write a test feature to an in-memory registry.
1548
- testFeature := registrytest .WriteContainer (t , registrytest .New (t ), "features/test-feature:latest" , features .TarLayerMediaType , map [string ]any {
1634
+ testFeature := registrytest .WriteContainer (t , registrytest .New (t ), emptyRemoteOpts , "features/test-feature:latest" , features .TarLayerMediaType , map [string ]any {
1549
1635
"install.sh" : `#!/bin/sh
1550
1636
echo "${MESSAGE}" > /root/message.txt` ,
1551
1637
"devcontainer-feature.json" : features.Spec {
0 commit comments