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

feat(ProfileInfo): JWT token expiration detection #2298

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

traeok
Copy link
Member

@traeok traeok commented Oct 8, 2024

What It Does

Fernando mentioned that extenders would benefit from having access to the JWT token expiration feature from Zowe Explorer, so I figured it made the most sense to put it the logic for it in ProfileInfo. That way, anyone using Imperative to access/manage profiles can leverage this functionality.

How to Test

Once merged, this can be tested in action after this PR is updated: zowe/zowe-explorer-vscode#3174

Here's a manual test to show the behavior of the function itself:

  • Checkout this branch and run npm run build && npm pack from the packages/imperative folder
  • Copy the zowe-imperative-8.1.0.tgz file from this folder and place it into a new folder outside of the repo
  • cd to the empty folder and run zowe config init --no-prompt && npm init -y && npm install zowe-imperative-8.1.0.tgz @zowe/secrets-for-zowe-sdk (you don't need secrets SDK, but its easier than getting around cred manager setup in ProfileInfo)
  • Copy this config and replace the contents of zowe.config.json:
{
    "$schema": "./zowe.schema.json",
    "profiles": {
        "zosmf": {
            "type": "zosmf",
            "properties": {
                "port": 1337
            }
        },
        "project_base": {
            "type": "base",
            "properties": {
                "host": "localhost",
                // this token expired in 2001
                // if you want to test an unexpired token, this one expires in 2128: 123.eyJleHAiOjUwMDAwMDAwMDB9.456
                "tokenValue": "123.eyJleHAiOjEwMDAwMDAwMDB9.456"
            }
        }
    },
    "defaults": {
        "zosmf": "zosmf",
        "base": "project_base"
    }
}
  • Save the following code snippet as script.mjs within this test folder and run it using node script.mjs
const { ProfileInfo } = await import("@zowe/imperative");
const profInfo = new ProfileInfo("zowe");
await profInfo.readProfilesFromDisk({ projectDir: process.cwd() });
console.log("token expired:", profInfo.hasTokenExpiredForProfile("zosmf"));

The script should output token expired: true.

Review Checklist
I certify that I have:

Additional Comments

Signed-off-by: Trae Yelovich <trae.yelovich@broadcom.com>
Copy link

codecov bot commented Oct 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.07%. Comparing base (a8a90f8) to head (29cde25).

Additional details and impacted files
@@           Coverage Diff            @@
##           master    #2298    +/-   ##
========================================
  Coverage   91.06%   91.07%            
========================================
  Files         628      628            
  Lines       17867    17887    +20     
  Branches     3735     3845   +110     
========================================
+ Hits        16271    16291    +20     
  Misses       1595     1595            
  Partials        1        1            

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Trae Yelovich <trae.yelovich@broadcom.com>
@traeok traeok force-pushed the feat/imperative/jwt-token-expiration branch from fbf581e to f52417e Compare October 8, 2024 21:38
Signed-off-by: Trae Yelovich <trae.yelovich@broadcom.com>
Signed-off-by: Trae Yelovich <trae.yelovich@broadcom.com>
Signed-off-by: Trae Yelovich <trae.yelovich@broadcom.com>
@traeok traeok marked this pull request as ready for review October 8, 2024 22:41
@traeok
Copy link
Member Author

traeok commented Oct 8, 2024

I don't have permissions on Zowe CLI to update the new issue reported by SonarCloud, but it is a false positive as argValue will almost always be type string. Even in some abnormal case where it isn't a string, all exceptions will be handled in the try/catch block.

@adam-wolfe adam-wolfe added this to the V3.1.0 milestone Oct 9, 2024
Signed-off-by: Trae Yelovich <trae.yelovich@broadcom.com>
Copy link

sonarcloud bot commented Oct 10, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Review/QA
Development

Successfully merging this pull request may close these issues.

3 participants