mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 19:11:25 +01:00
fix(auth): make logout reject only the credential tea stored
Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
6 files changed
+50
-28
No files matched your search
@@ -102,11 +102,23 @@ func TestRejectCredentialsAsksHelpersToEraseTheAccount(t *testing.T) {
|
||||
runner := System{}
|
||||
_, err := runner.Output(ctx, home, false, "config", "--global", "credential.helper", "!f() { echo \"op=$1\" >> '"+log+"'; cat >> '"+log+"'; }; f")
|
||||
require.NoError(t, err)
|
||||
store := filepath.Join(home, "git-credentials")
|
||||
_, err = runner.Output(ctx, home, false, "config", "--global", "--add", "credential.helper", "store --file="+store)
|
||||
require.NoError(t, err)
|
||||
own := "http://alice:own-password@localhost:3001\n"
|
||||
require.NoError(t, os.WriteFile(store, []byte(own+"http://alice:tea-token@localhost:3001/gitea/alice/project.git\n"), 0o600))
|
||||
require.Empty(t, HelperScope(ctx, runner, home, "http://localhost:3001"))
|
||||
require.NoError(t, RejectCredentials(ctx, runner, home, "http://localhost:3001/gitea", "alice"))
|
||||
require.NoError(t, RejectCredentials(ctx, runner, home, "http://localhost:3001/gitea", "alice", "tea-token"))
|
||||
data, err := os.ReadFile(log)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, "op=erase\nprotocol=http\nhost=localhost:3001\nusername=alice\n", string(data))
|
||||
require.Equal(t, "op=erase\nprotocol=http\nhost=localhost:3001\nusername=alice\npassword=tea-token\n", string(data))
|
||||
data, err = os.ReadFile(store)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, own, string(data), "only the copy of tea's token is erased")
|
||||
require.NoError(t, RejectCredentials(ctx, runner, home, "http://localhost:3001", "alice", ""))
|
||||
data, err = os.ReadFile(store)
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, own, string(data), "without a token nothing is erased")
|
||||
executable, err := os.Executable()
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, SetupCredentials(ctx, runner, CredentialSetup{Directory: home, Instance: "http://localhost:3001", Executable: executable}))
|
||||
|
||||
Reference in new issue
Block a user