(ctx context.Context, t *testctx.T)
| 1016 | } |
| 1017 | |
| 1018 | func (GitSuite) TestSubmoduleAuth(ctx context.Context, t *testctx.T) { |
| 1019 | c := connect(ctx, t) |
| 1020 | t.Cleanup(func() { _ = c.Close() }) |
| 1021 | |
| 1022 | authToken := c.SetSecret("submodule-test-token", "test-token-"+identity.NewID()) |
| 1023 | |
| 1024 | submoduleContent := c.Directory().WithNewFile("submodule.txt", "This is the submodule content") |
| 1025 | parentContent := c.Directory().WithNewFile("parent.txt", "This is the parent content") |
| 1026 | |
| 1027 | // Create bare parent + submodule repos in /srv |
| 1028 | // Git dance below is necessary: https://github.com/dagger/dagger/pull/10855#discussion_r2264174757 |
| 1029 | gitReposCtr := c.Container(). |
| 1030 | From(alpineImage). |
| 1031 | WithExec([]string{"apk", "add", "git"}). |
| 1032 | With(gitUserConfig). |
| 1033 | WithExec([]string{"sh", "-lc", "mkdir -p /srv && git init --bare /srv/submodule.git && git init --bare /srv/parent.git"}). |
| 1034 | WithDirectory("/tmp/sub", submoduleContent). |
| 1035 | WithExec([]string{"sh", "-lc", ` |
| 1036 | set -eux |
| 1037 | cd /tmp/sub |
| 1038 | git init |
| 1039 | git add . |
| 1040 | git commit -m 'Initial submodule commit' |
| 1041 | git remote add origin file:///srv/submodule.git |
| 1042 | git push -u origin main |
| 1043 | `}). |
| 1044 | WithDirectory("/tmp/parent", parentContent). |
| 1045 | WithExec([]string{"sh", "-lc", ` |
| 1046 | set -eux |
| 1047 | cd /tmp/parent |
| 1048 | git init |
| 1049 | git add . |
| 1050 | git commit -m 'Initial parent commit' |
| 1051 | git -c protocol.file.allow=always submodule add file:///srv/submodule.git sub |
| 1052 | git commit -m 'Add submodule (absolute url to fetch)' |
| 1053 | git config -f .gitmodules submodule.sub.url ../submodule.git |
| 1054 | git add .gitmodules |
| 1055 | git commit -m 'Make submodule URL relative' |
| 1056 | git remote add origin file:///srv/parent.git |
| 1057 | git push -u origin main |
| 1058 | # dumb HTTP needs server-info |
| 1059 | git --git-dir=/srv/submodule.git update-server-info |
| 1060 | git --git-dir=/srv/parent.git update-server-info |
| 1061 | `}) |
| 1062 | |
| 1063 | gitReposDir := gitReposCtr.Directory("/srv") |
| 1064 | |
| 1065 | t.Run("smart-http", func(ctx context.Context, t *testctx.T) { |
| 1066 | gitSrv, base := gitSmartHTTPServiceDirAuth(ctx, t, c, "", gitReposDir, "", authToken) |
| 1067 | parentURL := base + "/parent.git" |
| 1068 | |
| 1069 | t.Run("with auth", func(ctx context.Context, t *testctx.T) { |
| 1070 | tree := c.Git(parentURL, dagger.GitOpts{ |
| 1071 | ExperimentalServiceHost: gitSrv, |
| 1072 | HTTPAuthToken: authToken, |
| 1073 | }).Branch("main").Tree() |
| 1074 | |
| 1075 | txt, err := tree.File("parent.txt").Contents(ctx) |
nothing calls this directly
no test coverage detected