| 105 | } |
| 106 | |
| 107 | func TestGithubPluginAuth(t *testing.T) { |
| 108 | githubPlugin := githubPlugin{ |
| 109 | ref: flake.Ref{ |
| 110 | Type: "github", |
| 111 | Owner: "jetpack-io", |
| 112 | Repo: "devbox-plugins", |
| 113 | }, |
| 114 | name: "jetpack-io.devbox-plugins", |
| 115 | } |
| 116 | |
| 117 | expectedURL := "https://raw.githubusercontent.com/jetpack-io/devbox-plugins/master/test" |
| 118 | |
| 119 | t.Run("generate request for public Github repository", func(t *testing.T) { |
| 120 | t.Setenv("GITHUB_TOKEN", "") |
| 121 | url, err := githubPlugin.url("test") |
| 122 | assert.NoError(t, err) |
| 123 | actual, err := githubPlugin.request(url) |
| 124 | assert.NoError(t, err) |
| 125 | assert.Equal(t, expectedURL, actual.URL.String()) |
| 126 | assert.Equal(t, "", actual.Header.Get("Authorization")) |
| 127 | }) |
| 128 | |
| 129 | t.Run("generate request for private Github repository", func(t *testing.T) { |
| 130 | t.Setenv("GITHUB_TOKEN", "gh_abcd") |
| 131 | url, err := githubPlugin.url("test") |
| 132 | assert.NoError(t, err) |
| 133 | actual, err := githubPlugin.request(url) |
| 134 | assert.NoError(t, err) |
| 135 | assert.Equal(t, expectedURL, actual.URL.String()) |
| 136 | assert.Equal(t, "token gh_abcd", actual.Header.Get("Authorization")) |
| 137 | }) |
| 138 | } |
| 139 | |
| 140 | func TestGetRedactedAuthHeader(t *testing.T) { |
| 141 | testCases := []struct { |