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(daemon): create --save-token directory when not exist #5234

Merged
merged 4 commits into from
Feb 5, 2025

Conversation

hanabi1224
Copy link
Contributor

@hanabi1224 hanabi1224 commented Feb 5, 2025

Summary of changes

Changes introduced in this pull request:

  • create --save-token directory when not exist
  • improve error message

Reference issue to close (if applicable)

Closes #5233

Other information and links

Change checklist

  • I have performed a self-review of my own code,
  • I have made corresponding changes to the documentation. All new code adheres to the team's documentation standards,
  • I have added tests that prove my fix is effective or that my feature works (if possible),
  • I have made sure the CHANGELOG is up-to-date. All user-facing changes should be reflected in this document.

@hanabi1224 hanabi1224 changed the title fix(daemon): create --save-token diretory when not exist fix(daemon): create --save-token directory when not exist Feb 5, 2025
@hanabi1224 hanabi1224 marked this pull request as ready for review February 5, 2025 05:42
@hanabi1224 hanabi1224 requested a review from a team as a code owner February 5, 2025 05:42
@hanabi1224 hanabi1224 requested review from lemmih and sudo-shashank and removed request for a team February 5, 2025 05:42
@LesnyRumcajs
Copy link
Member

Let's cover it in tests, perhaps extending this:

#[test]
fn should_create_jwt_admin_token() {
let (config_file, data_dir) = create_tmp_config();
let token_path = data_dir.path().join("admin-token");
daemon()
.common_args()
.arg("--config")
.arg(config_file)
.arg("--encrypt-keystore")
.arg("false")
.arg("--save-token")
.arg(&token_path)
.assert()
.success();
// Grab the keystore and the private key
let keystore = KeyStore::new(KeyStoreConfig::Persistent(data_dir.path().to_owned())).unwrap();
let key_info = keystore.get(JWT_IDENTIFIER).unwrap();
let key = key_info.private_key();
// Validate the token
assert!(token_path.exists());
let token = std::fs::read_to_string(token_path).unwrap();
let allow = verify_token(&token, key).unwrap();
assert!(allow.contains(&"admin".to_owned()));
}

@hanabi1224
Copy link
Contributor Author

Let's cover it in tests, perhaps extending this:

@LesnyRumcajs test updated

@hanabi1224 hanabi1224 added this pull request to the merge queue Feb 5, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 5, 2025
@hanabi1224 hanabi1224 added this pull request to the merge queue Feb 5, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 5, 2025
@hanabi1224 hanabi1224 enabled auto-merge February 5, 2025 14:22
@hanabi1224 hanabi1224 added this pull request to the merge queue Feb 5, 2025
Merged via the queue into main with commit 7a4fe51 Feb 5, 2025
34 checks passed
@hanabi1224 hanabi1224 deleted the hm/create-save-token-dir branch February 5, 2025 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Forest daemon throws error when --save-token specifies a non-exisiting directory
3 participants