From 4a718c4d14eb9c4b7ce02aade7409c3f306764a7 Mon Sep 17 00:00:00 2001 From: Max Wittig Date: Tue, 13 Dec 2022 10:37:52 +0100 Subject: [PATCH] refactor: remove token validation Our self-hosted instance prefix is "CSC-" and has a length of 24 chars, so lets not assume that and let the validation take place with the user api call --- api/default.go | 12 ------------ api/default_test.go | 32 -------------------------------- commands/auth/status/status.go | 3 --- 3 files changed, 47 deletions(-) delete mode 100644 api/default.go delete mode 100644 api/default_test.go diff --git a/api/default.go b/api/default.go deleted file mode 100644 index 5a6bd257d..000000000 --- a/api/default.go +++ /dev/null @@ -1,12 +0,0 @@ -package api - -var DefaultListLimit = 30 - -// IsValidToken checks if a token provided is valid. -// The token string must be 26 characters in length and have the 'glpat-' -// prefix or just be 20 characters long to be recognized as a valid personal access token. -// -// TODO: check if token has minimum scopes required by glab -func IsValidToken(token string) bool { - return (len(token) == 26 && token[:6] == "glpat-") || len(token) == 20 -} diff --git a/api/default_test.go b/api/default_test.go deleted file mode 100644 index 35c0e025e..000000000 --- a/api/default_test.go +++ /dev/null @@ -1,32 +0,0 @@ -package api - -import "testing" - -func TestIsValidToken(t *testing.T) { - type args struct { - token string - } - tests := []struct { - name string - args args - want bool - }{ - { - name: "Token Is Valid", - args: args{token: "xxxxxxxxxxxxxxxxxxxx"}, - want: true, - }, - { - name: "Token Is inValid", - args: args{token: "123"}, - want: false, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := IsValidToken(tt.args.token); got != tt.want { - t.Errorf("IsValidToken() = %v, want %v", got, tt.want) - } - }) - } -} diff --git a/commands/auth/status/status.go b/commands/auth/status/status.go index 9924cbb4e..b70ddffd1 100644 --- a/commands/auth/status/status.go +++ b/commands/auth/status/status.go @@ -121,9 +121,6 @@ func statusRun(opts *StatusOpts) error { tokenDisplay = token } addMsg("%s Token: %s", c.GreenCheck(), tokenDisplay) - if !api.IsValidToken(token) { - addMsg("%s Invalid token provided", c.WarnIcon()) - } } else { addMsg("%s No token provided", c.FailedIcon()) } -- GitLab