compose-cli: fix PAT detection for PAT suggestion

This commit is contained in:
Matt Landis 2023-07-25 15:31:48 -04:00
Родитель 6b231d670b
Коммит accd15cc05
2 изменённых файлов: 12 добавлений и 4 удалений

Просмотреть файл

@ -30,9 +30,10 @@ const (
// patSuggestMsg is a message to suggest the use of PAT (personal access tokens).
patSuggestMsg = `Logging in with your password grants your terminal complete access to your account.
For better security, log in with a limited-privilege personal access token. Learn more at https://docs.docker.com/go/access-tokens/`
)
// patPrefix represents a docker personal access token prefix.
patPrefix = "dckrp_"
var (
patPrefixes = []string{"dckrp_", "dckr_pat_"}
)
// displayPATSuggestMsg displays a message suggesting users to use PATs instead of passwords to reduce scope.
@ -71,8 +72,10 @@ func isUsingPassword(pass string) bool {
if _, err := uuid.ParseUUID(pass); err == nil {
return false
}
for _, patPrefix := range patPrefixes {
if strings.HasPrefix(pass, patPrefix) {
return false
}
}
return true
}

Просмотреть файл

@ -89,6 +89,11 @@ func TestIsUsingPassword(t *testing.T) {
"dckrp_ee5607c41bcd",
false,
},
{
"prefixed personal access token",
"dckr_pat_ee5607c41bcd",
false,
},
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {