From 9d7a1ff59246f2a9f084676f4a35826dad0b1b74 Mon Sep 17 00:00:00 2001 From: Griffin Date: Sat, 3 Aug 2024 17:30:02 +0800 Subject: [PATCH] Fix accepting different token types (#60) --- lib/storage/tool_storage.rs | 4 ++-- src/cli/authenticate.rs | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/storage/tool_storage.rs b/lib/storage/tool_storage.rs index e430ea6..3fa5e1d 100644 --- a/lib/storage/tool_storage.rs +++ b/lib/storage/tool_storage.rs @@ -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); } } diff --git a/src/cli/authenticate.rs b/src/cli/authenticate.rs index f3813f6..9732aff 100644 --- a/src/cli/authenticate.rs +++ b/src/cli/authenticate.rs @@ -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." ) } }