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