Skip to content

Commit

Permalink
Fix accepting different token types (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
Midnightific committed Aug 3, 2024
1 parent 8345564 commit 9d7a1ff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
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

0 comments on commit 9d7a1ff

Please sign in to comment.