mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
fix: auth-decisions (follow gh: auth status exit code and GITEA_TOKEN account)
Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
5 files changed
+57
-11
No files matched your search
@@ -88,7 +88,7 @@ func TestAccountNamesMatchCaseInsensitively(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestEnvironmentCredentialVerifiesSelectedAccountBeforeMutation(t *testing.T) {
|
||||
for _, selection := range []string{"--user", "TEA_USER", "active instance account"} {
|
||||
for _, selection := range []string{"--user", "TEA_USER"} {
|
||||
t.Run(selection, func(t *testing.T) {
|
||||
reads, mutations := 0, 0
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -113,9 +113,6 @@ func TestEnvironmentCredentialVerifiesSelectedAccountBeforeMutation(t *testing.T
|
||||
if selection == "--user" {
|
||||
args = append(args, "--user", "bob")
|
||||
}
|
||||
if selection == "active instance account" {
|
||||
configureHost(t, deps, host, settings.Host{User: "bob", Users: tokenAccounts(settings.StoreKeyring, "bob")})
|
||||
}
|
||||
err := Execute(context.Background(), deps, args)
|
||||
require.ErrorContains(t, err, "does not belong to the selected account")
|
||||
require.Equal(t, clierr.Authentication, clierr.ExitCode(err))
|
||||
@@ -358,3 +355,24 @@ func TestRepositoryDiscoveryOutsideCheckoutWritesNoGitDiagnostics(t *testing.T)
|
||||
require.Empty(t, out.String())
|
||||
require.Empty(t, diagnostics.String())
|
||||
}
|
||||
|
||||
func TestEnvironmentCredentialOverridesTheActiveAccount(t *testing.T) {
|
||||
created := false
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
require.Equal(t, "token private-test-token", r.Header.Get("Authorization"))
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
if r.Method == http.MethodGet && r.URL.Path == "/base/api/v1/user" {
|
||||
_, _ = w.Write([]byte(`{"login":"alice"}`))
|
||||
return
|
||||
}
|
||||
created = true
|
||||
_, _ = w.Write([]byte(`{"id":9,"number":3,"title":"Issue","state":"open"}`))
|
||||
}))
|
||||
defer server.Close()
|
||||
deps, _, _ := testDeps(t)
|
||||
host := server.URL + "/base"
|
||||
deps.Getenv = envFunc(map[string]string{"TEA_HOST": host, "GITEA_TOKEN": "private-test-token"})
|
||||
configureHost(t, deps, host, settings.Host{User: "bob", Users: tokenAccounts(settings.StoreKeyring, "bob")})
|
||||
require.NoError(t, Execute(context.Background(), deps, []string{"issue", "create", "-R", "alice/project", "--title", "Issue", "--body", "Body", "--no-input", "--json"}))
|
||||
require.True(t, created)
|
||||
}
|
||||
Reference in new issue
Block a user