Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix accepting different token types #60

Merged
merged 6 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/storage/tool_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ impl ToolStorage {
// so look for and try to remove existing links that do not have the extension
if should_check_exe_extensions() {
for link_path in &mut link_paths {
if !has_exe_extension(&link_path) {
remove_file(&link_path).await?;
if !has_exe_extension(link_path.as_path()) {
remove_file(link_path.as_path()).await?;
*link_path = append_exe_extension(&link_path);
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/cli/authenticate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,14 @@ async fn verify_token_format(
// Verify the basic format of the token.
match provider {
ArtifactProvider::GitHub => {
// https://github.blog/2021-04-05-behind-githubs-new-authentication-token-formats/
if !token.starts_with("ghp_") && !token.starts_with("gho_") {
if token.len() < 4
|| &token[0..2] != "gh"
|| !token.chars().nth(2).unwrap().is_ascii_lowercase()
|| token.chars().nth(3).unwrap() != '_'
{
bail!(
"Invalid GitHub token format.\
\nGitHub tokens must start with 'ghp_' or 'gho_'."
\nGitHub tokens must start with 'gh' followed by a lowercase letter and an underscore."
)
}
}
Expand Down