dana-cli 0.0.0-stage → 0.0.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/dependabot.yml +43 -0
- package/.github/labeler.yml +30 -0
- package/.github/workflows/bump.yml +51 -0
- package/.github/workflows/ci-cd.yml +110 -0
- package/.github/workflows/dependabot-automerge-call.yml +13 -0
- package/.nvmrc +1 -0
- package/.prettierignore +4 -0
- package/.prettierrc +4 -0
- package/CODEOWNERS +5 -0
- package/README.md +50 -2
- package/bin/bump.js +48 -0
- package/eslint.config.mjs +12 -0
- package/images/vodScreen1.png +0 -0
- package/package.json +53 -5
- package/sonar-project.properties +20 -0
- package/tools/cli/README.md +51 -0
- package/tools/cli/__mocks__/fs/promises.cjs +4 -0
- package/tools/cli/bin/dana.js +3 -0
- package/tools/cli/dana_completion.sh +156 -0
- package/tools/cli/eslint.config.mjs +14 -0
- package/tools/cli/package.json +67 -0
- package/tools/cli/rollup.config.mjs +26 -0
- package/tools/cli/src/commands/addComponent/addMenu/add-menu.ts +65 -0
- package/tools/cli/src/commands/addComponent/addMenu/addMenuDefinition.ts +21 -0
- package/tools/cli/src/commands/addComponent/addRail/add-rail.ts +59 -0
- package/tools/cli/src/commands/addComponent/addRail/addRailDefinition.ts +34 -0
- package/tools/cli/src/commands/addComponent/addScreen/add-screen.ts +42 -0
- package/tools/cli/src/commands/addComponent/addScreen/addScreenDefinition.ts +17 -0
- package/tools/cli/src/commands/addComponent/addScrollView/add-scrollView.ts +48 -0
- package/tools/cli/src/commands/addComponent/addScrollView/addScrollViewDefinition.ts +16 -0
- package/tools/cli/src/commands/addComponent/config/ComponentConfig.ts +169 -0
- package/tools/cli/src/commands/addComponent/config/componentTypes.ts +38 -0
- package/tools/cli/src/commands/addComponent/const/componentConst.ts +20 -0
- package/tools/cli/src/commands/addComponent/const/defaultConfig.ts +28 -0
- package/tools/cli/src/commands/addComponent/const/navigationConst.ts +36 -0
- package/tools/cli/src/commands/addComponent/createComponent.ts +45 -0
- package/tools/cli/src/commands/addComponent/helper/ComponentHelper.ts +98 -0
- package/tools/cli/src/commands/addDevice/add-device.ts +106 -0
- package/tools/cli/src/commands/addDevice/addDeviceDefinition.ts +13 -0
- package/tools/cli/src/commands/addDevice/deviceConfig/androidtvConfig.ts +142 -0
- package/tools/cli/src/commands/addDevice/deviceConfig/configTypes.ts +44 -0
- package/tools/cli/src/commands/addDevice/deviceConfig/deviceConfig.ts +38 -0
- package/tools/cli/src/commands/addDevice/deviceConfig/titanosConfig.ts +17 -0
- package/tools/cli/src/commands/addDevice/deviceConfig/tizenConfig.ts +64 -0
- package/tools/cli/src/commands/addDevice/deviceConfig/tvosConfig.ts +50 -0
- package/tools/cli/src/commands/addDevice/deviceConfig/vidaaConfig.ts +17 -0
- package/tools/cli/src/commands/addDevice/deviceConfig/webosConfig.ts +64 -0
- package/tools/cli/src/commands/addDevice/helper/addDeviceHelper.ts +121 -0
- package/tools/cli/src/commands/addDianaSkills/add-dianaSkills.ts +55 -0
- package/tools/cli/src/commands/addDianaSkills/addDianaSkillsDefinition.ts +13 -0
- package/tools/cli/src/commands/addDianaSkills/dianaDependencies.ts +15 -0
- package/tools/cli/src/commands/addModule/add-module.ts +46 -0
- package/tools/cli/src/commands/addModule/addModuleDefinition.ts +17 -0
- package/tools/cli/src/commands/addModule/moduleConst.ts +18 -0
- package/tools/cli/src/commands/authentication/AuthenticationManager.ts +255 -0
- package/tools/cli/src/commands/authentication/authDefinition.ts +51 -0
- package/tools/cli/src/commands/authentication/authHook.ts +50 -0
- package/tools/cli/src/commands/authentication/authentConst.ts +6 -0
- package/tools/cli/src/commands/authentication/commands/get-packages-token.ts +40 -0
- package/tools/cli/src/commands/authentication/commands/login.ts +63 -0
- package/tools/cli/src/commands/authentication/commands/logout.ts +26 -0
- package/tools/cli/src/commands/authentication/commands/status.ts +47 -0
- package/tools/cli/src/commands/authentication/helper/CodeArtifactHelper.ts +66 -0
- package/tools/cli/src/commands/authentication/helper/CommandHelper.ts +9 -0
- package/tools/cli/src/commands/authentication/helper/CredentialsHelper.ts +176 -0
- package/tools/cli/src/commands/authentication/helper/SPM.ts +95 -0
- package/tools/cli/src/commands/authentication/tokenHook.ts +30 -0
- package/tools/cli/src/commands/commandHelp/customHelp.ts +31 -0
- package/tools/cli/src/commands/completion/completion.ts +53 -0
- package/tools/cli/src/commands/completion/completionDefinition.ts +16 -0
- package/tools/cli/src/commands/createApp/const/createAppTasks.ts +133 -0
- package/tools/cli/src/commands/createApp/const/setupConst.ts +16 -0
- package/tools/cli/src/commands/createApp/const/templateConst.ts +10 -0
- package/tools/cli/src/commands/createApp/createApp.ts +60 -0
- package/tools/cli/src/commands/createApp/createAppDefinition.ts +26 -0
- package/tools/cli/src/commands/createApp/helpers/CreateAppHelper.ts +167 -0
- package/tools/cli/src/commands/createApp/helpers/SetupChecker.ts +98 -0
- package/tools/cli/src/commands/hooks/checkDanaProjectHook.ts +30 -0
- package/tools/cli/src/commands/zip/zip.ts +26 -0
- package/tools/cli/src/commands/zip/zipDefinition.ts +13 -0
- package/tools/cli/src/common/commonConst.ts +1 -0
- package/tools/cli/src/common/const/deviceConst.ts +110 -0
- package/tools/cli/src/common/const/exitCodeConst.ts +12 -0
- package/tools/cli/src/common/helpers/CreateArchiveHelper.ts +55 -0
- package/tools/cli/src/common/helpers/CreateFileHelper.ts +199 -0
- package/tools/cli/src/common/helpers/InputValidator.ts +58 -0
- package/tools/cli/src/common/helpers/InstallHelper.ts +202 -0
- package/tools/cli/src/common/helpers/UpdateFileHelper.ts +239 -0
- package/tools/cli/src/common/helpers/UserInputGetter.ts +145 -0
- package/tools/cli/src/common/helpers/handlebarsHelper.ts +31 -0
- package/tools/cli/src/common/helpers/stringHelper.ts +25 -0
- package/tools/cli/src/common/translation/en.json +87 -0
- package/tools/cli/src/common/translation/translation.ts +6 -0
- package/tools/cli/src/common/types/helperTypes.ts +79 -0
- package/tools/cli/src/index.ts +16 -0
- package/tools/cli/src/program.ts +59 -0
- package/tools/cli/tests/commands/addComponent/addMenu/add-menu.test.ts +96 -0
- package/tools/cli/tests/commands/addComponent/addRail/add-rail.test.ts +57 -0
- package/tools/cli/tests/commands/addComponent/addScreen/add-screen.test.ts +55 -0
- package/tools/cli/tests/commands/addComponent/addScrollView/add-scrollView.test.ts +89 -0
- package/tools/cli/tests/commands/addComponent/config/ComponentConfig.test.ts +261 -0
- package/tools/cli/tests/commands/addComponent/createComponent.test.ts +87 -0
- package/tools/cli/tests/commands/addComponent/helper/ComponentHelper.test.ts +110 -0
- package/tools/cli/tests/commands/addDevice/add-device.test.ts +117 -0
- package/tools/cli/tests/commands/addDevice/deviceConfig/androidtvConfig.test.ts +184 -0
- package/tools/cli/tests/commands/addDevice/deviceConfig/deviceConfig.test.ts +30 -0
- package/tools/cli/tests/commands/addDevice/deviceConfig/titanosConfig.test.ts +20 -0
- package/tools/cli/tests/commands/addDevice/deviceConfig/tizenConfig.test.ts +63 -0
- package/tools/cli/tests/commands/addDevice/deviceConfig/tvosConfig.test.ts +47 -0
- package/tools/cli/tests/commands/addDevice/deviceConfig/vidaaConfig.test.ts +20 -0
- package/tools/cli/tests/commands/addDevice/deviceConfig/webosConfig.test.ts +74 -0
- package/tools/cli/tests/commands/addDevice/helper/addDeviceHelper.test.ts +144 -0
- package/tools/cli/tests/commands/addDianaSkills/add-dianaSkills.test.ts +72 -0
- package/tools/cli/tests/commands/addModule/add-module.test.ts +108 -0
- package/tools/cli/tests/commands/authentication/AuthenticationManager.test.ts +756 -0
- package/tools/cli/tests/commands/authentication/commands/authDefinition.test.ts +53 -0
- package/tools/cli/tests/commands/authentication/commands/authHook.test.ts +94 -0
- package/tools/cli/tests/commands/authentication/commands/get-packages-token.test.ts +69 -0
- package/tools/cli/tests/commands/authentication/commands/login.test.ts +170 -0
- package/tools/cli/tests/commands/authentication/commands/logout.test.ts +77 -0
- package/tools/cli/tests/commands/authentication/commands/status.test.ts +73 -0
- package/tools/cli/tests/commands/authentication/helper/CredentialsHelper.test.ts +352 -0
- package/tools/cli/tests/commands/authentication/helper/SPM.test.ts +229 -0
- package/tools/cli/tests/commands/cliHelp/customHelp.test.ts +24 -0
- package/tools/cli/tests/commands/completion/completion.test.ts +76 -0
- package/tools/cli/tests/commands/createApp/const/createAppTasks.test.ts +70 -0
- package/tools/cli/tests/commands/createApp/createApp.test.ts +116 -0
- package/tools/cli/tests/commands/createApp/helpers/CreateAppHelper.test.ts +197 -0
- package/tools/cli/tests/commands/createApp/helpers/SetupChecker.test.ts +152 -0
- package/tools/cli/tests/commands/createApp/helpers/fixtures/myApp/scripts/app/ui/screens/SplashScreen.js +70 -0
- package/tools/cli/tests/commands/hooks/checkDanaProjectHook.test.ts +55 -0
- package/tools/cli/tests/commands/zip/zip.test.ts +51 -0
- package/tools/cli/tests/common/helpers/CreateArchiveHelper.test.ts +69 -0
- package/tools/cli/tests/common/helpers/CreateFileHelper.test.ts +359 -0
- package/tools/cli/tests/common/helpers/InputValidator.test.ts +93 -0
- package/tools/cli/tests/common/helpers/InstallHelper.test.ts +262 -0
- package/tools/cli/tests/common/helpers/UpdateFileHelper.test.ts +288 -0
- package/tools/cli/tests/common/helpers/UserInputGetter.test.ts +182 -0
- package/tools/cli/tests/common/helpers/handlebarsHelper.test.ts +87 -0
- package/tools/cli/tests/common/helpers/stringHelper.test.ts +35 -0
- package/tools/cli/tests/program.test.ts +215 -0
- package/tools/cli/tsconfig.json +19 -0
- package/tools/cli/tsconfig.test.json +4 -0
- package/tools/cli/vitest.config.ts +4 -0
- package/tools/templates/app-template/.dana/.gitkeep +0 -0
- package/tools/templates/app-template/Gruntfile.js +31 -0
- package/tools/templates/app-template/README.md +17 -0
- package/tools/templates/app-template/app.config.json +56 -0
- package/tools/templates/app-template/editorconfigTemplate.hbs +18 -0
- package/tools/templates/app-template/eslintrc.jsonTemplate.hbs +5 -0
- package/tools/templates/app-template/gitignoreTemplate.hbs +27 -0
- package/tools/templates/app-template/i18n/LocaleStringEnUS.json +7 -0
- package/tools/templates/app-template/i18n/README.md +32 -0
- package/tools/templates/app-template/images/dana.png +0 -0
- package/tools/templates/app-template/images/dana_logo.png +0 -0
- package/tools/templates/app-template/images/dana_logo_light.png +0 -0
- package/tools/templates/app-template/images/loading.png +0 -0
- package/tools/templates/app-template/nvmrcTemplate.hbs +1 -0
- package/tools/templates/app-template/package.json +33 -0
- package/tools/templates/app-template/profiles/app.config.browser-css.json +16 -0
- package/tools/templates/app-template/profiles/app.config.browser-lightning.json +16 -0
- package/tools/templates/app-template/scripts/app/README.md +6 -0
- package/tools/templates/app-template/scripts/app/TemplateAppRoutes.js.hbs +18 -0
- package/tools/templates/app-template/scripts/app/app.js.hbs +17 -0
- package/tools/templates/app-template/scripts/app/theme/AppTheme.js +57 -0
- package/tools/templates/app-template/scripts/app/ui/screens/AppScreen.js +106 -0
- package/tools/templates/app-template/scripts/app/ui/screens/SplashScreen.js +70 -0
- package/tools/templates/app-template/scripts/app/ui/views/LoaderView.js +31 -0
- package/tools/templates/app-template/styles/fonts/Roboto-Bold.ttf +0 -0
- package/tools/templates/app-template/styles/fonts/Roboto-Regular.ttf +0 -0
- package/tools/templates/app-template/tests/README.md +70 -0
- package/tools/templates/app-template/tests/automation/features/splash.feature +5 -0
- package/tools/templates/app-template/tests/automation/init.js +20 -0
- package/tools/templates/app-template/tests/automation/steps-definitions/dictionary.js +31 -0
- package/tools/templates/app-template/tests/automation/steps-definitions/helpers.js +9 -0
- package/tools/templates/app-template/tests/unit/README.md +7 -0
- package/tools/templates/app-template/tests/unit/app/TemplateAppRoutes.js.hbs +24 -0
- package/tools/templates/assets/fonts/fa-solid-900.ttf +0 -0
- package/tools/templates/components/ButtonItemView.js.hbs +69 -0
- package/tools/templates/components/ButtonView.js.hbs +65 -0
- package/tools/templates/components/ScrollItemView.js.hbs +53 -0
- package/tools/templates/components/ScrollView.js.hbs +43 -0
- package/tools/templates/components/TileView.js.hbs +55 -0
- package/tools/templates/components/screen.js.hbs +74 -0
- package/tools/templates/components/settings.js.hbs +74 -0
- package/tools/templates/components/vod.js.hbs +104 -0
- package/tools/templates/components/wtvMenuListView.js.hbs +38 -0
- package/tools/templates/components/wtvRailListView.js.hbs +44 -0
- package/tools/templates/index.ts +3 -0
- package/tools/templates/mocks/menuMock.json +29 -0
- package/tools/templates/mocks/railMock.json +101 -0
- package/tools/templates/mocks/scrollViewMock.json +165 -0
- package/tools/templates/modules/fip/images/12.png +0 -0
- package/tools/templates/modules/fip/images/audioD.png +0 -0
- package/tools/templates/modules/fip/package.json +5 -0
- package/tools/templates/modules/fip/scripts/FipModule.js +19 -0
- package/tools/templates/modules/fip/scripts/FipRoutes.js +19 -0
- package/tools/templates/modules/fip/scripts/services/mock/fipMock.json +12 -0
- package/tools/templates/modules/fip/scripts/ui/screens/FipScreen.js +169 -0
- package/tools/templates/modules/fip/scripts/ui/views/FipContentInfoView.js +77 -0
- package/tools/templates/modules/fip/scripts/ui/views/InfoDetailImageView.js +35 -0
- package/tools/templates/modules/fip/scripts/ui/views/InfoDetailTextView.js +39 -0
- package/tools/templates/modules/fip/scripts/ui/views/InfoListView.js +57 -0
- package/tools/templates/modules/fip/scripts/ui/views/PlayButtonView.js +63 -0
- package/tools/templates/modules/home/package.json +5 -0
- package/tools/templates/modules/home/scripts/HomeModule.js +19 -0
- package/tools/templates/modules/home/scripts/HomeRoutes.js +19 -0
- package/tools/templates/modules/home/scripts/services/mock/highlightMock.json +40 -0
- package/tools/templates/modules/home/scripts/services/mock/homeScrollViewMock.json +170 -0
- package/tools/templates/modules/home/scripts/ui/screens/HomeScreen.js +258 -0
- package/tools/templates/modules/home/scripts/ui/views/highlight/DotsListItemView.js +37 -0
- package/tools/templates/modules/home/scripts/ui/views/highlight/DotsListView.js +22 -0
- package/tools/templates/modules/home/scripts/ui/views/highlight/HighlightContentDescriptionView.js +99 -0
- package/tools/templates/modules/home/scripts/ui/views/highlight/HighlightPlayButtonView.js +63 -0
- package/tools/templates/modules/home/scripts/ui/views/highlight/HighlightRailItemView.js +186 -0
- package/tools/templates/modules/home/scripts/ui/views/scrollview/HomeMockTileView.js +67 -0
- package/tools/templates/modules/home/scripts/ui/views/scrollview/HomeRailScrollView.js +53 -0
- package/tools/templates/modules/home/scripts/ui/views/scrollview/HomeScrollView.js +22 -0
- package/tools/templates/modules/menu/images/profile.png +0 -0
- package/tools/templates/modules/menu/package.json +5 -0
- package/tools/templates/modules/menu/scripts/MenuModule.js +18 -0
- package/tools/templates/modules/menu/scripts/MenuRoutes.js +14 -0
- package/tools/templates/modules/menu/scripts/services/menuMock.json +24 -0
- package/tools/templates/modules/menu/scripts/ui/const/MenuIcons.js +16 -0
- package/tools/templates/modules/menu/scripts/ui/views/MenuButtonView.js +101 -0
- package/tools/templates/modules/menu/scripts/ui/views/MenuListView.js +60 -0
- package/tools/templates/modules/menu/scripts/ui/views/MenuView.js +87 -0
- package/tools/templates/modules/menu/scripts/ui/views/ProfileImageView.js +30 -0
- package/tools/templates/modules/player/package.json +5 -0
- package/tools/templates/modules/player/scripts/PlayerModule.js +19 -0
- package/tools/templates/modules/player/scripts/PlayerRoutes.js +19 -0
- package/tools/templates/modules/player/scripts/ui/const/PlayerIcons.js +19 -0
- package/tools/templates/modules/player/scripts/ui/screens/PlayerScreen.js +361 -0
- package/tools/templates/modules/player/scripts/ui/views/PlayerControlButtonView.js +69 -0
- package/tools/templates/modules/player/scripts/ui/views/PlayerControlsView.js +173 -0
- package/tools/templates/modules/player/scripts/ui/views/ProgressBarView.js +53 -0
- package/tools/templates/modules/search/package.json +5 -0
- package/tools/templates/modules/search/scripts/SearchModule.js +18 -0
- package/tools/templates/modules/search/scripts/SearchRoutes.js +16 -0
- package/tools/templates/modules/search/scripts/ui/const/EnglishKeyboardData.js +31 -0
- package/tools/templates/modules/search/scripts/ui/const/SearchIcons.js +14 -0
- package/tools/templates/modules/search/scripts/ui/const/SearchKeyboardLayout.js +19 -0
- package/tools/templates/modules/search/scripts/ui/primitives/SearchTextPrimitive.js +36 -0
- package/tools/templates/modules/search/scripts/ui/screens/SearchScreen.js +234 -0
- package/tools/templates/modules/search/scripts/ui/services/MockSearchService.js +39 -0
- package/tools/templates/modules/search/scripts/ui/services/SearchVirtualKeyboardService.js +33 -0
- package/tools/templates/modules/search/scripts/ui/services/mock/searchMock.json +172 -0
- package/tools/templates/modules/search/scripts/ui/views/SearchView.js +62 -0
- package/tools/templates/modules/search/scripts/ui/views/keyboard/SearchKeyboardRowItemView.js +92 -0
- package/tools/templates/modules/search/scripts/ui/views/keyboard/SearchKeyboardRowListView.js +33 -0
- package/tools/templates/modules/search/scripts/ui/views/keyboard/SearchKeyboardView.js +63 -0
- package/tools/templates/modules/search/scripts/ui/views/rail/SearchScrollRailView.js +53 -0
- package/tools/templates/modules/search/scripts/ui/views/rail/SearchScrollView.js +22 -0
- package/tools/templates/modules/search/scripts/ui/views/rail/SearchTileView.js +68 -0
- package/tools/templates/modules/search/styles/styles/fonts/fa-solid-900.ttf +0 -0
- package/tools/templates/modules/settings/package.json +5 -0
- package/tools/templates/modules/settings/scripts/SettingsModule.js +19 -0
- package/tools/templates/modules/settings/scripts/SettingsRoutes.js +19 -0
- package/tools/templates/modules/settings/scripts/ui/screens/SettingsScreen.js +200 -0
- package/tools/templates/modules/settings/scripts/ui/views/SettingsListItemView.js +85 -0
- package/tools/templates/modules/settings/scripts/ui/views/SettingsListView.js +56 -0
- package/tools/templates/modules/vod/package.json +5 -0
- package/tools/templates/modules/vod/scripts/VodModule.js +19 -0
- package/tools/templates/modules/vod/scripts/VodRoutes.js +19 -0
- package/tools/templates/modules/vod/scripts/services/mock/scrollViewMock.json +172 -0
- package/tools/templates/modules/vod/scripts/ui/screens/VodScreen.js +204 -0
- package/tools/templates/modules/vod/scripts/ui/views/MockTileView.js +69 -0
- package/tools/templates/modules/vod/scripts/ui/views/RailScrollItemView.js +53 -0
- package/tools/templates/modules/vod/scripts/ui/views/VodScrollView.js +22 -0
- package/tools/templates/package.json +14 -0
- package/tools/templates/profiles/app.config.androidtv.json +17 -0
- package/tools/templates/profiles/app.config.titanos.json +24 -0
- package/tools/templates/profiles/app.config.tizen.json +52 -0
- package/tools/templates/profiles/app.config.tvos.json +18 -0
- package/tools/templates/profiles/app.config.vidaa.json +24 -0
- package/tools/templates/profiles/app.config.webos.json +21 -0
- package/tools/templates/tutorial/modules/fip/package.json +4 -0
- package/tools/templates/tutorial/modules/fip/scripts/FipModule.js +18 -0
- package/tools/templates/tutorial/modules/fip/scripts/FipRoutes.js +19 -0
- package/tools/templates/tutorial/modules/fip/scripts/ui/screens/FipContentScreen.js +146 -0
- package/tools/templates/tutorial/modules/fip/scripts/ui/views/ElevatorView.js +66 -0
- package/tools/templates/tutorial/modules/fip/scripts/ui/views/FipContentInfoView.js +90 -0
- package/tools/templates/tutorial/modules/fip/scripts/ui/views/PlayButtonView.js +58 -0
- package/tools/templates/tutorial/vendors/customBE/package.json +5 -0
- package/tools/templates/tutorial/vendors/customBE/scripts/datas/contents.json +749 -0
- package/tools/templates/tutorial/vendors/customBE/scripts/services/CustomBEVodService.js +70 -0
- package/tsconfig.json +8 -0
- package/vitest.config.ts +19 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Command } from "commander";
|
|
2
|
+
import addAuthDefinition from "@/commands/authentication/authDefinition.js";
|
|
3
|
+
import { beforeEach, expect, vi } from "vitest";
|
|
4
|
+
import { LOGIN_ERROR } from "@/common/const/exitCodeConst.js";
|
|
5
|
+
import login from "@/commands/authentication/commands/login.js";
|
|
6
|
+
|
|
7
|
+
vi.mock("@/commands/authentication/commands/login.js");
|
|
8
|
+
vi.mock("@clack/prompts");
|
|
9
|
+
let program: Command;
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
program = new Command();
|
|
12
|
+
program.addCommand(addAuthDefinition());
|
|
13
|
+
});
|
|
14
|
+
afterEach(() => {
|
|
15
|
+
vi.restoreAllMocks();
|
|
16
|
+
});
|
|
17
|
+
interface CommandWithHooks extends Command {
|
|
18
|
+
_lifeCycleHooks: {
|
|
19
|
+
preAction: { name: string }[];
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
describe("loginCmd", () => {
|
|
24
|
+
it("should be well formatted", () => {
|
|
25
|
+
const loginCmd = program.commands[0].commands[0];
|
|
26
|
+
|
|
27
|
+
expect(loginCmd.options.length).toBe(4);
|
|
28
|
+
expect(loginCmd.name()).toBe("login");
|
|
29
|
+
const hooks = (loginCmd as CommandWithHooks)._lifeCycleHooks;
|
|
30
|
+
expect(hooks.preAction.length).toBe(1);
|
|
31
|
+
});
|
|
32
|
+
it("should not call login after tokenHook failure", async () => {
|
|
33
|
+
const mockExit = vi.spyOn(process, "exit").mockImplementation((code) => {
|
|
34
|
+
throw new Error(`Process exit with code ${code}`);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const options = [
|
|
38
|
+
["auth", "login", "-t", "token", "-o", "org"], // Invalid PAT
|
|
39
|
+
["auth", "login", "-t", "dana_token"], // Missing org
|
|
40
|
+
];
|
|
41
|
+
|
|
42
|
+
await Promise.all(
|
|
43
|
+
options.map((option) => expect(program.parseAsync(option, { from: "user" })).rejects.toThrow()),
|
|
44
|
+
);
|
|
45
|
+
expect(mockExit).toHaveBeenCalledTimes(2);
|
|
46
|
+
expect(mockExit).toHaveBeenCalledWith(LOGIN_ERROR);
|
|
47
|
+
expect(vi.mocked(login)).toHaveBeenCalledTimes(0);
|
|
48
|
+
});
|
|
49
|
+
it("should call login after tokenHook success", async () => {
|
|
50
|
+
await program.parseAsync(["auth", "login", "-t", "dana_token", "-o", "org"], { from: "user" });
|
|
51
|
+
expect(vi.mocked(login)).toHaveBeenCalled();
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2014-2025 Wiztivi - contact@wiztivi.com
|
|
3
|
+
* All Rights Reserved
|
|
4
|
+
*
|
|
5
|
+
* All information contained herein is proprietary and confidential.
|
|
6
|
+
* Dissemination of this information or reproduction of this file or material, via any medium is strictly forbidden unless
|
|
7
|
+
* prior written permission is obtained from Wiztivi.
|
|
8
|
+
* No warranty, explicit or implicit, provided.
|
|
9
|
+
* This software MAY NOT be used, modified or rewritten without prior written permission from Wiztivi.
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
AwsCredentials,
|
|
15
|
+
CodeArtifactToken,
|
|
16
|
+
CredentialsHelper,
|
|
17
|
+
DanaToken,
|
|
18
|
+
} from "@/commands/authentication/helper/CredentialsHelper.js";
|
|
19
|
+
import { authHook } from "@/commands/authentication/authHook.js";
|
|
20
|
+
import { AuthCredentials, AuthenticationManager } from "@/commands/authentication/AuthenticationManager.js";
|
|
21
|
+
|
|
22
|
+
vi.mock("@/commands/authentication/helper/CredentialsHelper.js");
|
|
23
|
+
vi.mock("@/commands/authentication/AuthenticationManager.js");
|
|
24
|
+
|
|
25
|
+
const mockDate = new Date("2023-01-01T00:00:00.000Z");
|
|
26
|
+
let credentials: AuthCredentials;
|
|
27
|
+
beforeEach(() => {
|
|
28
|
+
vi.useFakeTimers();
|
|
29
|
+
|
|
30
|
+
vi.setSystemTime(mockDate);
|
|
31
|
+
credentials = {
|
|
32
|
+
org: "testOrg",
|
|
33
|
+
isRemote: false,
|
|
34
|
+
dana: {
|
|
35
|
+
id_token: "testTokenDana",
|
|
36
|
+
refresh_token: "testRefreshToken",
|
|
37
|
+
} as DanaToken,
|
|
38
|
+
aws: {
|
|
39
|
+
accessKeyId: "testAccessKeyId",
|
|
40
|
+
secretAccessKey: "testSecretAccessKey",
|
|
41
|
+
sessionToken: "testSessionToken",
|
|
42
|
+
expiration: "",
|
|
43
|
+
identityId: "",
|
|
44
|
+
},
|
|
45
|
+
codeArtifact: {
|
|
46
|
+
token: "testTokenNpm",
|
|
47
|
+
expiration: new Date("2024-01-01T00:00:00.000Z"),
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
afterEach(() => {
|
|
53
|
+
vi.resetAllMocks();
|
|
54
|
+
vi.useRealTimers();
|
|
55
|
+
});
|
|
56
|
+
describe("authHook", () => {
|
|
57
|
+
it("should log to codeartifact", async () => {
|
|
58
|
+
const tokens = [
|
|
59
|
+
{ testName: "no npm creds", codeArtifact: null },
|
|
60
|
+
{ testName: "expired creds", codeArtifact: { token: "testTokenNpm", expiration: new Date(mockDate) } },
|
|
61
|
+
];
|
|
62
|
+
for (const token of tokens) {
|
|
63
|
+
credentials.codeArtifact = token as unknown as CodeArtifactToken;
|
|
64
|
+
vi.mocked(CredentialsHelper.get).mockResolvedValue(credentials);
|
|
65
|
+
|
|
66
|
+
await authHook();
|
|
67
|
+
expect(vi.mocked(AuthenticationManager.refresh)).not.toHaveBeenCalled();
|
|
68
|
+
expect(vi.mocked(AuthenticationManager.loginCodeArtifact)).toHaveBeenCalled();
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
it("should refresh because aws token expired", async () => {
|
|
72
|
+
credentials.aws = { expiration: "2022-01-01T00:00:00.000Z" } as AwsCredentials;
|
|
73
|
+
vi.mocked(CredentialsHelper.get).mockResolvedValue(credentials);
|
|
74
|
+
|
|
75
|
+
await authHook();
|
|
76
|
+
expect(vi.mocked(AuthenticationManager.refresh)).toHaveBeenCalled();
|
|
77
|
+
expect(vi.mocked(AuthenticationManager.loginCodeArtifact)).not.toHaveBeenCalled();
|
|
78
|
+
});
|
|
79
|
+
it("should refresh because dana token expired", async () => {
|
|
80
|
+
vi.mocked(CredentialsHelper.get).mockResolvedValue(credentials);
|
|
81
|
+
vi.mocked(AuthenticationManager.isTokenExpired).mockReturnValue(true);
|
|
82
|
+
await authHook();
|
|
83
|
+
expect(vi.mocked(AuthenticationManager.refresh)).toHaveBeenCalled();
|
|
84
|
+
expect(vi.mocked(AuthenticationManager.loginCodeArtifact)).not.toHaveBeenCalled();
|
|
85
|
+
});
|
|
86
|
+
it("should refresh and login to npm", async () => {
|
|
87
|
+
credentials.codeArtifact = { token: "testTokenNpm", expiration: new Date("2022-01-01T00:00:00.000Z") };
|
|
88
|
+
vi.mocked(CredentialsHelper.get).mockResolvedValue(credentials);
|
|
89
|
+
vi.mocked(AuthenticationManager.isTokenExpired).mockReturnValue(true);
|
|
90
|
+
await authHook();
|
|
91
|
+
expect(vi.mocked(AuthenticationManager.refresh)).toHaveBeenCalled();
|
|
92
|
+
expect(vi.mocked(AuthenticationManager.loginCodeArtifact)).toHaveBeenCalled();
|
|
93
|
+
});
|
|
94
|
+
});
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { vi } from "vitest";
|
|
2
|
+
import { AuthCredentials } from "@/commands/authentication/AuthenticationManager.js";
|
|
3
|
+
import { CredentialsHelper } from "@/commands/authentication/helper/CredentialsHelper.js";
|
|
4
|
+
import { getPackagesToken } from "@/commands/authentication/commands/get-packages-token.js";
|
|
5
|
+
import { createCodeArtifactClient } from "@/commands/authentication/helper/CodeArtifactHelper.js";
|
|
6
|
+
import { CodeartifactClient } from "@aws-sdk/client-codeartifact";
|
|
7
|
+
import { DOMAIN, DOMAIN_OWNER } from "@/commands/authentication/authentConst.js";
|
|
8
|
+
|
|
9
|
+
let mockCreds: AuthCredentials;
|
|
10
|
+
|
|
11
|
+
vi.mock("@/commands/authentication/AuthenticationManager.js");
|
|
12
|
+
vi.mock("@/commands/authentication/helper/CredentialsHelper.js");
|
|
13
|
+
vi.mock("@/commands/authentication/helper/CodeArtifactHelper.js", () => {
|
|
14
|
+
const clientMock = {
|
|
15
|
+
send: vi.fn() as typeof CodeartifactClient.prototype.send,
|
|
16
|
+
};
|
|
17
|
+
return {
|
|
18
|
+
createCodeArtifactClient: vi.fn().mockReturnValue(clientMock),
|
|
19
|
+
};
|
|
20
|
+
});
|
|
21
|
+
vi.spyOn(process, "exit");
|
|
22
|
+
vi.spyOn(console, "log");
|
|
23
|
+
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
vi.resetAllMocks();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe("get-packages-token", () => {
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
mockCreds = {
|
|
31
|
+
isRemote: false,
|
|
32
|
+
org: "org",
|
|
33
|
+
aws: {
|
|
34
|
+
identityId: "identityId",
|
|
35
|
+
accessKeyId: "accessKeyId",
|
|
36
|
+
secretAccessKey: "secretAccessKey",
|
|
37
|
+
sessionToken: "sessionToken",
|
|
38
|
+
expiration: "expiration",
|
|
39
|
+
},
|
|
40
|
+
dana: {
|
|
41
|
+
id_token: "id_token",
|
|
42
|
+
access_token: "access_token",
|
|
43
|
+
refresh_token: "refresh_token",
|
|
44
|
+
expires_in: 0,
|
|
45
|
+
token_type: "token_type",
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
vi.mocked(CredentialsHelper.get).mockImplementation((org?: string) => {
|
|
49
|
+
if (org) {
|
|
50
|
+
return Promise.resolve({ ...mockCreds, org });
|
|
51
|
+
} else {
|
|
52
|
+
return Promise.resolve(mockCreds);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("should log the code artifact token", async () => {
|
|
58
|
+
const client = createCodeArtifactClient(mockCreds.aws);
|
|
59
|
+
vi.mocked(client.send).mockResolvedValueOnce({ authorizationToken: "auth_token" } as unknown as void);
|
|
60
|
+
await getPackagesToken({ target: "android" });
|
|
61
|
+
|
|
62
|
+
expect(vi.mocked(console.log)).toHaveBeenCalledExactlyOnceWith("auth_token");
|
|
63
|
+
expect(vi.mocked(client.send)).toHaveBeenCalledOnce();
|
|
64
|
+
expect(vi.mocked(client.send).mock.calls[0][0].input).toStrictEqual({
|
|
65
|
+
domain: DOMAIN,
|
|
66
|
+
domainOwner: DOMAIN_OWNER,
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
});
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { vi } from "vitest";
|
|
2
|
+
import { AuthCredentials, AuthenticationManager } from "@/commands/authentication/AuthenticationManager.js";
|
|
3
|
+
import login from "@/commands/authentication/commands/login.js";
|
|
4
|
+
import { CredentialsHelper } from "@/commands/authentication/helper/CredentialsHelper.js";
|
|
5
|
+
import { LOGIN_ERROR } from "@/common/const/exitCodeConst.js";
|
|
6
|
+
|
|
7
|
+
let mockCreds: AuthCredentials;
|
|
8
|
+
|
|
9
|
+
vi.mock("@/commands/authentication/AuthenticationManager.js");
|
|
10
|
+
vi.mock("@/commands/authentication/helper/CredentialsHelper.js");
|
|
11
|
+
vi.spyOn(process, "exit");
|
|
12
|
+
|
|
13
|
+
describe("login", () => {
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
mockCreds = {
|
|
16
|
+
org: "org",
|
|
17
|
+
isRemote: false,
|
|
18
|
+
aws: {
|
|
19
|
+
identityId: "identityId",
|
|
20
|
+
accessKeyId: "accessKeyId",
|
|
21
|
+
secretAccessKey: "secretAccessKey",
|
|
22
|
+
sessionToken: "sessionToken",
|
|
23
|
+
expiration: "expiration",
|
|
24
|
+
},
|
|
25
|
+
dana: {
|
|
26
|
+
id_token: "id_token",
|
|
27
|
+
access_token: "access_token",
|
|
28
|
+
refresh_token: "refresh_token",
|
|
29
|
+
expires_in: 0,
|
|
30
|
+
token_type: "token_type",
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
vi.mocked(AuthenticationManager.login).mockResolvedValue(mockCreds);
|
|
34
|
+
vi.mocked(AuthenticationManager.loginCodeArtifact).mockResolvedValue({
|
|
35
|
+
expiration: new Date(0),
|
|
36
|
+
token: "token",
|
|
37
|
+
});
|
|
38
|
+
vi.mocked(CredentialsHelper.get).mockImplementation((org?: string) => {
|
|
39
|
+
if (org) {
|
|
40
|
+
return Promise.resolve({ ...mockCreds, org });
|
|
41
|
+
} else {
|
|
42
|
+
return Promise.resolve(mockCreds);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
vi.mocked(AuthenticationManager.isTokenExpired).mockResolvedValue(true);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
afterEach(() => {
|
|
50
|
+
vi.resetAllMocks();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("should login to specified organization if no credentials", async () => {
|
|
54
|
+
vi.mocked(CredentialsHelper.get).mockResolvedValueOnce({ isRemote: false, org: "foo" });
|
|
55
|
+
await login({ org: "foo" });
|
|
56
|
+
expect(vi.mocked(AuthenticationManager.login)).toHaveBeenCalledExactlyOnceWith({
|
|
57
|
+
organization: "foo",
|
|
58
|
+
isRemote: false,
|
|
59
|
+
userPort: undefined,
|
|
60
|
+
});
|
|
61
|
+
expect(vi.mocked(AuthenticationManager.loginCodeArtifact)).toHaveBeenCalledExactlyOnceWith("foo", {
|
|
62
|
+
identityId: "identityId",
|
|
63
|
+
accessKeyId: "accessKeyId",
|
|
64
|
+
secretAccessKey: "secretAccessKey",
|
|
65
|
+
sessionToken: "sessionToken",
|
|
66
|
+
expiration: "expiration",
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("should login remotely if no credentials", async () => {
|
|
71
|
+
vi.mocked(CredentialsHelper.get).mockResolvedValueOnce({ isRemote: true, org: "foo" });
|
|
72
|
+
await login({ org: "foo", remote: true });
|
|
73
|
+
expect(vi.mocked(AuthenticationManager.login)).toHaveBeenCalledExactlyOnceWith({
|
|
74
|
+
isRemote: true,
|
|
75
|
+
organization: "foo",
|
|
76
|
+
userPort: undefined,
|
|
77
|
+
});
|
|
78
|
+
expect(vi.mocked(AuthenticationManager.loginCodeArtifact)).toHaveBeenCalledExactlyOnceWith("foo", {
|
|
79
|
+
identityId: "identityId",
|
|
80
|
+
accessKeyId: "accessKeyId",
|
|
81
|
+
secretAccessKey: "secretAccessKey",
|
|
82
|
+
sessionToken: "sessionToken",
|
|
83
|
+
expiration: "expiration",
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("should login remotely with specified port if no credentials", async () => {
|
|
88
|
+
vi.mocked(CredentialsHelper.get).mockResolvedValueOnce({ isRemote: true, org: "foo" });
|
|
89
|
+
await login({ org: "foo", port: 9002, remote: true });
|
|
90
|
+
expect(vi.mocked(AuthenticationManager.login)).toHaveBeenCalledExactlyOnceWith({
|
|
91
|
+
organization: "foo",
|
|
92
|
+
isRemote: true,
|
|
93
|
+
userPort: 9002,
|
|
94
|
+
});
|
|
95
|
+
expect(vi.mocked(AuthenticationManager.loginCodeArtifact)).toHaveBeenCalledExactlyOnceWith("foo", {
|
|
96
|
+
identityId: "identityId",
|
|
97
|
+
accessKeyId: "accessKeyId",
|
|
98
|
+
secretAccessKey: "secretAccessKey",
|
|
99
|
+
sessionToken: "sessionToken",
|
|
100
|
+
expiration: "expiration",
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("should login to default organization if none asked if no credentials", async () => {
|
|
105
|
+
vi.mocked(CredentialsHelper.get).mockResolvedValueOnce({ isRemote: false, org: "org" });
|
|
106
|
+
await login({});
|
|
107
|
+
expect(vi.mocked(AuthenticationManager.login)).toHaveBeenCalledExactlyOnceWith({
|
|
108
|
+
organization: "org",
|
|
109
|
+
isRemote: false,
|
|
110
|
+
userPort: undefined,
|
|
111
|
+
});
|
|
112
|
+
expect(vi.mocked(AuthenticationManager.loginCodeArtifact)).toHaveBeenCalledExactlyOnceWith("org", {
|
|
113
|
+
identityId: "identityId",
|
|
114
|
+
accessKeyId: "accessKeyId",
|
|
115
|
+
secretAccessKey: "secretAccessKey",
|
|
116
|
+
sessionToken: "sessionToken",
|
|
117
|
+
expiration: "expiration",
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("should refresh credentials if dana creds expired", async () => {
|
|
122
|
+
vi.mocked(AuthenticationManager.refresh).mockResolvedValueOnce({
|
|
123
|
+
aws: {
|
|
124
|
+
identityId: "identityId",
|
|
125
|
+
accessKeyId: "accessKeyId",
|
|
126
|
+
secretAccessKey: "secretAccessKey",
|
|
127
|
+
sessionToken: "sessionToken",
|
|
128
|
+
expiration: "expiration",
|
|
129
|
+
},
|
|
130
|
+
codeArtifact: undefined,
|
|
131
|
+
dana: { access_token: "", expires_in: 0, id_token: "", refresh_token: "refresh_token", token_type: "" },
|
|
132
|
+
isRemote: false,
|
|
133
|
+
org: "",
|
|
134
|
+
port: 0,
|
|
135
|
+
});
|
|
136
|
+
vi.mocked(CredentialsHelper.get).mockResolvedValueOnce({
|
|
137
|
+
isRemote: false,
|
|
138
|
+
org: "org",
|
|
139
|
+
dana: {
|
|
140
|
+
id_token: "id_token",
|
|
141
|
+
access_token: "access_token",
|
|
142
|
+
refresh_token: "refresh_token",
|
|
143
|
+
expires_in: 0,
|
|
144
|
+
token_type: "id",
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
await login({});
|
|
148
|
+
expect(vi.mocked(AuthenticationManager.refresh)).toHaveBeenCalledExactlyOnceWith(
|
|
149
|
+
"org",
|
|
150
|
+
"refresh_token",
|
|
151
|
+
false,
|
|
152
|
+
undefined,
|
|
153
|
+
);
|
|
154
|
+
expect(vi.mocked(AuthenticationManager.loginCodeArtifact)).toHaveBeenCalledExactlyOnceWith("org", {
|
|
155
|
+
identityId: "identityId",
|
|
156
|
+
accessKeyId: "accessKeyId",
|
|
157
|
+
secretAccessKey: "secretAccessKey",
|
|
158
|
+
sessionToken: "sessionToken",
|
|
159
|
+
expiration: "expiration",
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it("should exit on error", async () => {
|
|
164
|
+
vi.mocked(CredentialsHelper.get).mockResolvedValueOnce({ isRemote: false, org: "org" });
|
|
165
|
+
vi.mocked(AuthenticationManager.login).mockRejectedValueOnce(new Error("REJECTED"));
|
|
166
|
+
vi.mocked(process.exit).mockImplementation(((_) => {}) as typeof process.exit);
|
|
167
|
+
await login({});
|
|
168
|
+
expect(vi.mocked(process.exit)).toHaveBeenCalledExactlyOnceWith(LOGIN_ERROR);
|
|
169
|
+
});
|
|
170
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { vi } from "vitest";
|
|
2
|
+
import { AuthCredentials, AuthenticationManager } from "@/commands/authentication/AuthenticationManager.js";
|
|
3
|
+
import { CredentialsHelper } from "@/commands/authentication/helper/CredentialsHelper.js";
|
|
4
|
+
import logout from "@/commands/authentication/commands/logout.js";
|
|
5
|
+
|
|
6
|
+
let mockCreds: AuthCredentials;
|
|
7
|
+
|
|
8
|
+
vi.mock("@/commands/authentication/AuthenticationManager.js");
|
|
9
|
+
vi.mock("@/commands/authentication/helper/CredentialsHelper.js");
|
|
10
|
+
vi.spyOn(process, "exit");
|
|
11
|
+
|
|
12
|
+
describe("logout", () => {
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
mockCreds = {
|
|
15
|
+
isRemote: false,
|
|
16
|
+
org: "org",
|
|
17
|
+
aws: {
|
|
18
|
+
identityId: "identityId",
|
|
19
|
+
accessKeyId: "accessKeyId",
|
|
20
|
+
secretAccessKey: "secretAccessKey",
|
|
21
|
+
sessionToken: "sessionToken",
|
|
22
|
+
expiration: "expiration",
|
|
23
|
+
},
|
|
24
|
+
dana: {
|
|
25
|
+
id_token: "id_token",
|
|
26
|
+
access_token: "access_token",
|
|
27
|
+
refresh_token: "refresh_token",
|
|
28
|
+
expires_in: 0,
|
|
29
|
+
token_type: "token_type",
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
vi.mocked(AuthenticationManager.login).mockResolvedValue(mockCreds);
|
|
33
|
+
vi.mocked(AuthenticationManager.loginNPM).mockResolvedValue();
|
|
34
|
+
vi.mocked(CredentialsHelper.get).mockImplementation((org?: string) => {
|
|
35
|
+
if (org) {
|
|
36
|
+
return Promise.resolve({ ...mockCreds, org });
|
|
37
|
+
} else {
|
|
38
|
+
return Promise.resolve(mockCreds);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
afterEach(() => {
|
|
44
|
+
vi.resetAllMocks();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("should logout from specified organization with credentials", async () => {
|
|
48
|
+
await logout({ org: "foo" });
|
|
49
|
+
expect(vi.mocked(AuthenticationManager.logout)).toHaveBeenCalledExactlyOnceWith("foo", mockCreds.dana, false);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("should logout from specified organization without credentials", async () => {
|
|
53
|
+
vi.mocked(CredentialsHelper.get).mockResolvedValueOnce({
|
|
54
|
+
aws: undefined,
|
|
55
|
+
dana: undefined,
|
|
56
|
+
isRemote: false,
|
|
57
|
+
npm: undefined,
|
|
58
|
+
port: 0,
|
|
59
|
+
org: "foo",
|
|
60
|
+
});
|
|
61
|
+
await logout({ org: "foo" });
|
|
62
|
+
expect(vi.mocked(AuthenticationManager.logout)).toHaveBeenCalledExactlyOnceWith("foo", undefined, false);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("should logout from specified organization without credentials and in remote", async () => {
|
|
66
|
+
vi.mocked(CredentialsHelper.get).mockResolvedValueOnce({
|
|
67
|
+
aws: undefined,
|
|
68
|
+
dana: undefined,
|
|
69
|
+
isRemote: true,
|
|
70
|
+
npm: undefined,
|
|
71
|
+
port: 0,
|
|
72
|
+
org: "foo",
|
|
73
|
+
});
|
|
74
|
+
await logout({ org: "foo" });
|
|
75
|
+
expect(vi.mocked(AuthenticationManager.logout)).toHaveBeenCalledExactlyOnceWith("foo", undefined, true);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import * as prompts from "@clack/prompts";
|
|
2
|
+
import jwt from "jsonwebtoken";
|
|
3
|
+
import { status } from "@/commands/authentication/commands/status.js";
|
|
4
|
+
import { CredentialsHelper, DanaToken } from "@/commands/authentication/helper/CredentialsHelper.js";
|
|
5
|
+
import { LOGIN_STATUS } from "@/commands/authentication/commands/status.js";
|
|
6
|
+
|
|
7
|
+
vi.mock("@clack/prompts");
|
|
8
|
+
vi.mock("jsonwebtoken");
|
|
9
|
+
|
|
10
|
+
describe("auth status", () => {
|
|
11
|
+
afterEach(() => {
|
|
12
|
+
vi.resetAllMocks();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("should display the user is not logged in", async () => {
|
|
16
|
+
vi.spyOn(CredentialsHelper, "get").mockReturnValueOnce({
|
|
17
|
+
org: "org",
|
|
18
|
+
isRemote: false,
|
|
19
|
+
} as unknown as ReturnType<typeof CredentialsHelper.get>);
|
|
20
|
+
|
|
21
|
+
const result = await status();
|
|
22
|
+
|
|
23
|
+
expect(prompts.log.success).not.toHaveBeenCalled();
|
|
24
|
+
expect(prompts.log.error).toHaveBeenCalledWith("You're not logged in. Please run 'dana auth login' command");
|
|
25
|
+
expect(result).toEqual(LOGIN_STATUS.NOT_LOGGED);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("should display the user is logged in", async () => {
|
|
29
|
+
vi.spyOn(CredentialsHelper, "get").mockResolvedValueOnce({
|
|
30
|
+
org: "test",
|
|
31
|
+
isRemote: false,
|
|
32
|
+
dana: {
|
|
33
|
+
id_token: "xxx",
|
|
34
|
+
} as DanaToken,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
vi.mocked(jwt.decode).mockReturnValueOnce({
|
|
38
|
+
given_name: "John",
|
|
39
|
+
family_name: "Doe",
|
|
40
|
+
email: "john.doe@example.com",
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const result = await status();
|
|
44
|
+
|
|
45
|
+
expect(prompts.log.success).toHaveBeenCalledWith(expect.stringContaining("You're currently logged in to Dana"));
|
|
46
|
+
expect(prompts.log.success).toHaveBeenCalledWith(expect.stringContaining("John Doe"));
|
|
47
|
+
expect(prompts.log.success).toHaveBeenCalledWith(expect.stringContaining("john.doe@example.com"));
|
|
48
|
+
expect(result).toEqual(LOGIN_STATUS.LOGGED);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("should display the token has expired", async () => {
|
|
52
|
+
vi.spyOn(CredentialsHelper, "get").mockResolvedValueOnce({
|
|
53
|
+
org: "test",
|
|
54
|
+
isRemote: false,
|
|
55
|
+
dana: {
|
|
56
|
+
id_token: "xxx",
|
|
57
|
+
} as DanaToken,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
vi.mocked(jwt.decode).mockReturnValueOnce({
|
|
61
|
+
given_name: "John",
|
|
62
|
+
family_name: "Doe",
|
|
63
|
+
email: "john.doe@example.com",
|
|
64
|
+
exp: 1756387634, // 28/08/2025 13:27
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const result = await status();
|
|
68
|
+
|
|
69
|
+
expect(prompts.log.success).not.toHaveBeenCalled();
|
|
70
|
+
expect(prompts.log.error).toHaveBeenCalledWith(expect.stringContaining("Your token has expired"));
|
|
71
|
+
expect(result).toEqual(LOGIN_STATUS.TOKEN_EXPIRED);
|
|
72
|
+
});
|
|
73
|
+
});
|