dana-cli 0.0.0-stage → 0.0.25
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 +66 -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,756 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, Mock } from "vitest";
|
|
2
|
+
import { AuthenticationManager } from "@/commands/authentication/AuthenticationManager.js";
|
|
3
|
+
import { CredentialsHelper } from "@/commands/authentication/helper/CredentialsHelper.js";
|
|
4
|
+
import getPort from "get-port";
|
|
5
|
+
import express from "express";
|
|
6
|
+
import open from "open";
|
|
7
|
+
import jwt from "jsonwebtoken";
|
|
8
|
+
import { execSync } from "node:child_process";
|
|
9
|
+
import { vol } from "memfs";
|
|
10
|
+
import {
|
|
11
|
+
createCodeArtifactClient,
|
|
12
|
+
formatRepositoryString,
|
|
13
|
+
getRepositoryEndpoint,
|
|
14
|
+
} from "@/commands/authentication/helper/CodeArtifactHelper.js";
|
|
15
|
+
import { CodeartifactClient } from "@aws-sdk/client-codeartifact";
|
|
16
|
+
import {
|
|
17
|
+
ensureSPMDirectoriesExists,
|
|
18
|
+
updateSPMRegistries,
|
|
19
|
+
updateSPMToken,
|
|
20
|
+
} from "@/commands/authentication/helper/SPM.js";
|
|
21
|
+
|
|
22
|
+
process.env.HOME = "/HOME";
|
|
23
|
+
|
|
24
|
+
interface MockedExpressApp {
|
|
25
|
+
listen: ReturnType<typeof vi.fn>;
|
|
26
|
+
get: ReturnType<typeof vi.fn>;
|
|
27
|
+
set: ReturnType<typeof vi.fn>;
|
|
28
|
+
disable: ReturnType<typeof vi.fn>;
|
|
29
|
+
__triggerCallback: (req: Request, res: Response) => void;
|
|
30
|
+
__getMockServer: () => {
|
|
31
|
+
foo: string;
|
|
32
|
+
close: ReturnType<typeof vi.fn>;
|
|
33
|
+
closeAllConnections: ReturnType<typeof vi.fn>;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const mockQuery = {
|
|
38
|
+
query: {
|
|
39
|
+
aws: JSON.stringify({}),
|
|
40
|
+
token: JSON.stringify({}),
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
let requestReq = {};
|
|
45
|
+
const requestRes = { send: vi.fn() };
|
|
46
|
+
|
|
47
|
+
vi.mock("node:fs/promises");
|
|
48
|
+
vi.mock("@clack/prompts");
|
|
49
|
+
vi.mock("jsonwebtoken", () => {
|
|
50
|
+
return {
|
|
51
|
+
default: {
|
|
52
|
+
decode: vi.fn(),
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
vi.mock("open", () => {
|
|
58
|
+
return {
|
|
59
|
+
default: vi.fn(),
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
vi.mock("get-port", () => {
|
|
64
|
+
return {
|
|
65
|
+
default: vi.fn(),
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
vi.mock("node:child_process", () => {
|
|
70
|
+
return {
|
|
71
|
+
execSync: vi.fn(),
|
|
72
|
+
spawnSync: vi.fn(),
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
vi.mock("@/commands/authentication/helper/CodeArtifactHelper.js", () => {
|
|
76
|
+
return {
|
|
77
|
+
createCodeArtifactClient: vi.fn().mockReturnValue({
|
|
78
|
+
send: vi.fn,
|
|
79
|
+
}),
|
|
80
|
+
getRepositoryEndpoint: vi.fn(),
|
|
81
|
+
formatRepositoryString: vi.fn(),
|
|
82
|
+
};
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
vi.mock("@/commands/authentication/helper/CredentialsHelper.js", () => {
|
|
86
|
+
return {
|
|
87
|
+
CredentialsHelper: { store: vi.fn(), delete: vi.fn(), updateCodeArtifactToken: vi.fn() },
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
vi.mock("@/commands/authentication/helper/SPM.js", () => {
|
|
92
|
+
return {
|
|
93
|
+
ensureSPMDirectoriesExists: vi.fn(),
|
|
94
|
+
updateSPMRegistries: vi.fn(),
|
|
95
|
+
updateSPMToken: vi.fn(),
|
|
96
|
+
};
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
vi.mock("express", () => {
|
|
100
|
+
let routeHandler: ((req: Request, res: Response) => void) | null = null;
|
|
101
|
+
|
|
102
|
+
const mockServer = {
|
|
103
|
+
close: vi.fn(),
|
|
104
|
+
closeAllConnections: vi.fn(),
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const triggerCallback = (req: Request, res: Response) => {
|
|
108
|
+
if (routeHandler) {
|
|
109
|
+
routeHandler(req, res);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const mockApp = {
|
|
114
|
+
listen: vi.fn(() => mockServer),
|
|
115
|
+
get: vi.fn().mockImplementation((route: string, handler: (req: Request, res: Response) => void) => {
|
|
116
|
+
if (route === "/callback") {
|
|
117
|
+
routeHandler = handler;
|
|
118
|
+
}
|
|
119
|
+
}),
|
|
120
|
+
set: vi.fn(),
|
|
121
|
+
disable: vi.fn(),
|
|
122
|
+
__triggerCallback: triggerCallback,
|
|
123
|
+
__getMockServer: () => mockServer,
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
default: vi.fn(() => mockApp),
|
|
128
|
+
};
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
vi.mocked(getPort).mockResolvedValue(3000);
|
|
132
|
+
|
|
133
|
+
afterEach(() => {
|
|
134
|
+
vi.clearAllMocks();
|
|
135
|
+
vol.reset();
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe("AuthenticationManager", () => {
|
|
139
|
+
describe("login", () => {
|
|
140
|
+
describe("success flow with credentials", () => {
|
|
141
|
+
it("should complete the login flow successfully with provided org", async () => {
|
|
142
|
+
requestReq = mockQuery;
|
|
143
|
+
|
|
144
|
+
const mockApp = vi.mocked(express)() as unknown as MockedExpressApp;
|
|
145
|
+
const loginPromise = AuthenticationManager.login({ organization: "foo", isRemote: false });
|
|
146
|
+
|
|
147
|
+
// Trigger callback after starting login
|
|
148
|
+
mockApp.__triggerCallback(requestReq as Request, requestRes as unknown as Response);
|
|
149
|
+
|
|
150
|
+
await loginPromise;
|
|
151
|
+
|
|
152
|
+
expect(vi.mocked(open)).toHaveBeenCalledExactlyOnceWith(
|
|
153
|
+
"https://api.foo.dana-framework.com/login?port=3000",
|
|
154
|
+
);
|
|
155
|
+
expect(mockApp.listen).toHaveBeenCalledExactlyOnceWith(3000);
|
|
156
|
+
expect(mockApp.disable).toHaveBeenCalledWith("x-powered-by");
|
|
157
|
+
|
|
158
|
+
const mockServer = mockApp.__getMockServer();
|
|
159
|
+
expect(mockServer.closeAllConnections).toHaveBeenCalledOnce();
|
|
160
|
+
expect(mockServer.close).toHaveBeenCalledOnce();
|
|
161
|
+
expect(vi.mocked(CredentialsHelper.store)).toHaveBeenCalledOnce();
|
|
162
|
+
expect(requestRes.send).toHaveBeenCalledWith("Login successful! You can close this window.");
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("should store and resolve credentials received in /callback", async () => {
|
|
166
|
+
const danaToken = {
|
|
167
|
+
id_token: "id_token",
|
|
168
|
+
access_token: "access_token",
|
|
169
|
+
refresh_token: "refresh_token",
|
|
170
|
+
expires_in: 1,
|
|
171
|
+
token_type: "token_type",
|
|
172
|
+
};
|
|
173
|
+
const awsCreds = {
|
|
174
|
+
identityId: "identityId",
|
|
175
|
+
accessKeyId: "accessKeyId",
|
|
176
|
+
secretAccessKey: "secretAccessKey",
|
|
177
|
+
sessionToken: "sessionToken",
|
|
178
|
+
expiration: "expiration",
|
|
179
|
+
};
|
|
180
|
+
requestReq = {
|
|
181
|
+
query: {
|
|
182
|
+
token: JSON.stringify(danaToken),
|
|
183
|
+
aws: JSON.stringify(awsCreds),
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
const mockApp = vi.mocked(express)() as unknown as MockedExpressApp;
|
|
188
|
+
const loginPromise = AuthenticationManager.login({
|
|
189
|
+
organization: "foo",
|
|
190
|
+
isRemote: false,
|
|
191
|
+
userPort: undefined,
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
mockApp.__triggerCallback(requestReq as Request, requestRes as unknown as Response);
|
|
195
|
+
|
|
196
|
+
const result = await loginPromise;
|
|
197
|
+
|
|
198
|
+
expect(vi.mocked(CredentialsHelper.store)).toHaveBeenCalledExactlyOnceWith(
|
|
199
|
+
{
|
|
200
|
+
aws: awsCreds,
|
|
201
|
+
dana: danaToken,
|
|
202
|
+
org: "foo",
|
|
203
|
+
isRemote: false,
|
|
204
|
+
port: undefined,
|
|
205
|
+
},
|
|
206
|
+
false,
|
|
207
|
+
undefined,
|
|
208
|
+
);
|
|
209
|
+
expect(result).toStrictEqual({
|
|
210
|
+
aws: awsCreds,
|
|
211
|
+
dana: danaToken,
|
|
212
|
+
org: "foo",
|
|
213
|
+
port: undefined,
|
|
214
|
+
isRemote: false,
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it("should store and resolve credentials + keep if it is a remote machine with port that received in /callback", async () => {
|
|
219
|
+
const danaToken = {
|
|
220
|
+
id_token: "id_token",
|
|
221
|
+
access_token: "access_token",
|
|
222
|
+
refresh_token: "refresh_token",
|
|
223
|
+
expires_in: 1,
|
|
224
|
+
token_type: "token_type",
|
|
225
|
+
};
|
|
226
|
+
const awsCreds = {
|
|
227
|
+
identityId: "identityId",
|
|
228
|
+
accessKeyId: "accessKeyId",
|
|
229
|
+
secretAccessKey: "secretAccessKey",
|
|
230
|
+
sessionToken: "sessionToken",
|
|
231
|
+
expiration: "expiration",
|
|
232
|
+
};
|
|
233
|
+
requestReq = {
|
|
234
|
+
query: {
|
|
235
|
+
token: JSON.stringify(danaToken),
|
|
236
|
+
aws: JSON.stringify(awsCreds),
|
|
237
|
+
},
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
const mockApp = vi.mocked(express)() as unknown as MockedExpressApp;
|
|
241
|
+
const loginPromise = AuthenticationManager.login({
|
|
242
|
+
organization: "foo",
|
|
243
|
+
isRemote: true,
|
|
244
|
+
userPort: 9002,
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
mockApp.__triggerCallback(requestReq as Request, requestRes as unknown as Response);
|
|
248
|
+
|
|
249
|
+
const result = await loginPromise;
|
|
250
|
+
|
|
251
|
+
expect(vi.mocked(CredentialsHelper.store)).toHaveBeenCalledExactlyOnceWith(
|
|
252
|
+
{
|
|
253
|
+
aws: awsCreds,
|
|
254
|
+
dana: danaToken,
|
|
255
|
+
isRemote: true,
|
|
256
|
+
port: 9002,
|
|
257
|
+
org: "foo",
|
|
258
|
+
},
|
|
259
|
+
true,
|
|
260
|
+
9002,
|
|
261
|
+
);
|
|
262
|
+
expect(result).toStrictEqual({
|
|
263
|
+
aws: awsCreds,
|
|
264
|
+
dana: danaToken,
|
|
265
|
+
org: "foo",
|
|
266
|
+
isRemote: true,
|
|
267
|
+
port: 9002,
|
|
268
|
+
});
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
describe("error handling with credentials", () => {
|
|
273
|
+
it("should handle callback error", async () => {
|
|
274
|
+
requestReq = {
|
|
275
|
+
query: { error: "error-occurred" },
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
const mockApp = vi.mocked(express)() as unknown as MockedExpressApp;
|
|
279
|
+
const loginPromise = AuthenticationManager.login({ organization: "foo", isRemote: true });
|
|
280
|
+
|
|
281
|
+
// Trigger the callback with error data
|
|
282
|
+
mockApp.__triggerCallback(requestReq as Request, requestRes as unknown as Response);
|
|
283
|
+
|
|
284
|
+
await expect(loginPromise).rejects.toThrow("error-occurred");
|
|
285
|
+
|
|
286
|
+
const mockServer = mockApp.__getMockServer();
|
|
287
|
+
expect(mockServer.closeAllConnections).toHaveBeenCalled();
|
|
288
|
+
expect(mockServer.close).toHaveBeenCalled();
|
|
289
|
+
expect(requestRes.send).toHaveBeenCalledWith("Login failed. Check the CLI for details.");
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
it("should handle response error", async () => {
|
|
293
|
+
requestReq = {
|
|
294
|
+
query: { token: "NOT_JSON" },
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
const mockApp = vi.mocked(express)() as unknown as MockedExpressApp;
|
|
298
|
+
const loginPromise = AuthenticationManager.login({ organization: "foo", isRemote: true });
|
|
299
|
+
|
|
300
|
+
mockApp.__triggerCallback(requestReq as Request, requestRes as unknown as Response);
|
|
301
|
+
|
|
302
|
+
await expect(loginPromise).rejects.toThrow("Unexpected token 'N'");
|
|
303
|
+
|
|
304
|
+
const mockServer = mockApp.__getMockServer();
|
|
305
|
+
expect(mockServer.closeAllConnections).toHaveBeenCalled();
|
|
306
|
+
expect(mockServer.close).toHaveBeenCalled();
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
describe("success flow with PAT", () => {
|
|
310
|
+
it("should complete the login flow successfully with provided org and pat token", async () => {
|
|
311
|
+
vi.spyOn(global, "fetch").mockResolvedValue({
|
|
312
|
+
ok: true,
|
|
313
|
+
json: vi.fn().mockResolvedValue({
|
|
314
|
+
aws: {
|
|
315
|
+
accessKeyId: "accessKeyId",
|
|
316
|
+
expiration: "expiration",
|
|
317
|
+
identityId: "identityId",
|
|
318
|
+
secretAccessKey: "secretAccessKey",
|
|
319
|
+
sessionToken: "sessionToken",
|
|
320
|
+
},
|
|
321
|
+
}),
|
|
322
|
+
} as unknown as Response);
|
|
323
|
+
|
|
324
|
+
const result = await AuthenticationManager.login({
|
|
325
|
+
organization: "foo",
|
|
326
|
+
isRemote: false,
|
|
327
|
+
userPort: undefined,
|
|
328
|
+
patToken: "dana_patToken",
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
332
|
+
"https://api.foo.dana-framework.com/login?patToken=dana_patToken",
|
|
333
|
+
);
|
|
334
|
+
|
|
335
|
+
expect(result).toStrictEqual({
|
|
336
|
+
aws: {
|
|
337
|
+
accessKeyId: "accessKeyId",
|
|
338
|
+
expiration: "expiration",
|
|
339
|
+
identityId: "identityId",
|
|
340
|
+
secretAccessKey: "secretAccessKey",
|
|
341
|
+
sessionToken: "sessionToken",
|
|
342
|
+
},
|
|
343
|
+
org: "foo",
|
|
344
|
+
isRemote: false,
|
|
345
|
+
port: undefined,
|
|
346
|
+
patToken: "dana_patToken",
|
|
347
|
+
});
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
describe("error handling with PAT", () => {
|
|
351
|
+
it("should throw an error if the response is not ok", async () => {
|
|
352
|
+
vi.spyOn(global, "fetch").mockResolvedValue({
|
|
353
|
+
ok: false,
|
|
354
|
+
statusText: "Internal Server Error",
|
|
355
|
+
} as unknown as Response);
|
|
356
|
+
|
|
357
|
+
return expect(
|
|
358
|
+
AuthenticationManager.login({
|
|
359
|
+
organization: "foo",
|
|
360
|
+
isRemote: false,
|
|
361
|
+
userPort: undefined,
|
|
362
|
+
patToken: "dana_patToken",
|
|
363
|
+
}),
|
|
364
|
+
).rejects.toThrow("PAT authentication failed: Internal Server Error");
|
|
365
|
+
});
|
|
366
|
+
});
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
// ... rest of your tests remain the same
|
|
370
|
+
describe("logout", () => {
|
|
371
|
+
it("should open url with no id / refresh token", async () => {
|
|
372
|
+
await AuthenticationManager.logout("org");
|
|
373
|
+
expect(vi.mocked(open).mock.calls[0][0]).toMatch(/.*\/logout$/);
|
|
374
|
+
expect(vi.mocked(CredentialsHelper.delete)).toHaveBeenCalledExactlyOnceWith("org");
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
it("should open url with id_token", async () => {
|
|
378
|
+
await AuthenticationManager.logout("org", {
|
|
379
|
+
id_token: "id_token",
|
|
380
|
+
});
|
|
381
|
+
expect(vi.mocked(open)).toHaveBeenCalledOnce();
|
|
382
|
+
expect(vi.mocked(open).mock.calls[0][0]).toMatch("logout?id_token=id_token");
|
|
383
|
+
expect(vi.mocked(CredentialsHelper.delete)).toHaveBeenCalledExactlyOnceWith("org");
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
it("should open url with refresh_token", async () => {
|
|
387
|
+
await AuthenticationManager.logout("org", {
|
|
388
|
+
refresh_token: "refresh_token",
|
|
389
|
+
});
|
|
390
|
+
expect(vi.mocked(open)).toHaveBeenCalledOnce();
|
|
391
|
+
expect(vi.mocked(open).mock.calls[0][0]).toMatch("logout?refresh_token=refresh_token");
|
|
392
|
+
expect(vi.mocked(CredentialsHelper.delete)).toHaveBeenCalledExactlyOnceWith("org");
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
it("should open url with id_token & refresh_token", async () => {
|
|
396
|
+
await AuthenticationManager.logout("org", {
|
|
397
|
+
id_token: "id_token",
|
|
398
|
+
refresh_token: "refresh_token",
|
|
399
|
+
});
|
|
400
|
+
expect(vi.mocked(open)).toHaveBeenCalledOnce();
|
|
401
|
+
expect(vi.mocked(open).mock.calls[0][0]).toMatch("logout?id_token=id_token&refresh_token=refresh_token");
|
|
402
|
+
expect(vi.mocked(CredentialsHelper.delete)).toHaveBeenCalledExactlyOnceWith("org");
|
|
403
|
+
});
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
describe("refresh", () => {
|
|
407
|
+
beforeEach(() => {
|
|
408
|
+
global.fetch = vi.fn();
|
|
409
|
+
AuthenticationManager.login = vi.fn();
|
|
410
|
+
});
|
|
411
|
+
afterEach(() => {
|
|
412
|
+
vi.restoreAllMocks();
|
|
413
|
+
});
|
|
414
|
+
it("should call login if failed to refresh", async () => {
|
|
415
|
+
vi.mocked(global.fetch).mockResolvedValueOnce({
|
|
416
|
+
ok: false,
|
|
417
|
+
} as Response);
|
|
418
|
+
await AuthenticationManager.refresh("org", "token", false);
|
|
419
|
+
|
|
420
|
+
expect(vi.mocked(AuthenticationManager.login)).toHaveBeenCalledExactlyOnceWith({
|
|
421
|
+
organization: "org",
|
|
422
|
+
isRemote: false,
|
|
423
|
+
userPort: undefined,
|
|
424
|
+
});
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
it("should call return / store refreshed credentials", async () => {
|
|
428
|
+
const danaToken = {
|
|
429
|
+
id_token: "id_token",
|
|
430
|
+
access_token: "access_token",
|
|
431
|
+
refresh_token: "refresh_token",
|
|
432
|
+
expires_in: 1,
|
|
433
|
+
token_type: "token_type",
|
|
434
|
+
};
|
|
435
|
+
const awsCreds = {
|
|
436
|
+
identityId: "identityId",
|
|
437
|
+
accessKeyId: "accessKeyId",
|
|
438
|
+
secretAccessKey: "secretAccessKey",
|
|
439
|
+
sessionToken: "sessionToken",
|
|
440
|
+
expiration: "expiration",
|
|
441
|
+
};
|
|
442
|
+
vi.mocked(global.fetch).mockResolvedValueOnce({
|
|
443
|
+
ok: true,
|
|
444
|
+
json: vi.fn().mockResolvedValueOnce({ aws: awsCreds, token: danaToken }),
|
|
445
|
+
} as unknown as Response);
|
|
446
|
+
const result = await AuthenticationManager.refresh("org", "token", false);
|
|
447
|
+
|
|
448
|
+
expect(result).toStrictEqual({
|
|
449
|
+
org: "org",
|
|
450
|
+
aws: awsCreds,
|
|
451
|
+
dana: { ...danaToken, refresh_token: "token" },
|
|
452
|
+
isRemote: false,
|
|
453
|
+
port: undefined,
|
|
454
|
+
});
|
|
455
|
+
expect(vi.mocked(CredentialsHelper.store)).toHaveBeenCalledExactlyOnceWith(
|
|
456
|
+
{
|
|
457
|
+
org: "org",
|
|
458
|
+
aws: awsCreds,
|
|
459
|
+
dana: { ...danaToken, refresh_token: "token" },
|
|
460
|
+
isRemote: false,
|
|
461
|
+
port: undefined,
|
|
462
|
+
},
|
|
463
|
+
false,
|
|
464
|
+
undefined,
|
|
465
|
+
);
|
|
466
|
+
});
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
describe("isTokenExpired", () => {
|
|
470
|
+
beforeEach(() => {
|
|
471
|
+
vi.useFakeTimers({ now: 1000 });
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
afterEach(() => {
|
|
475
|
+
vi.useRealTimers();
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
it("should return true if token is expired", () => {
|
|
479
|
+
vi.mocked(jwt.decode).mockReturnValueOnce({ exp: 0 });
|
|
480
|
+
expect(AuthenticationManager.isTokenExpired("fake_token")).toBe(true);
|
|
481
|
+
});
|
|
482
|
+
|
|
483
|
+
it("should return true if token has no expiration", () => {
|
|
484
|
+
vi.mocked(jwt.decode).mockReturnValueOnce({});
|
|
485
|
+
expect(AuthenticationManager.isTokenExpired("fake_token")).toBe(true);
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
it("should return false if token is not expired", () => {
|
|
489
|
+
vi.mocked(jwt.decode).mockReturnValueOnce({ exp: 2 });
|
|
490
|
+
expect(AuthenticationManager.isTokenExpired("fake_token")).toBe(false);
|
|
491
|
+
});
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
describe("loginCodeArtifact", () => {
|
|
495
|
+
let sendMock: Mock;
|
|
496
|
+
const awsCreds = {
|
|
497
|
+
accessKeyId: "accessKeyId",
|
|
498
|
+
expiration: "expiration",
|
|
499
|
+
identityId: "identityId",
|
|
500
|
+
secretAccessKey: "secretAccessKey",
|
|
501
|
+
sessionToken: "sessionToken",
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
beforeEach(() => {
|
|
505
|
+
sendMock = vi.fn();
|
|
506
|
+
vi.mocked(createCodeArtifactClient).mockReturnValueOnce({
|
|
507
|
+
send: sendMock,
|
|
508
|
+
} as unknown as CodeartifactClient);
|
|
509
|
+
vi.spyOn(AuthenticationManager, "loginGradle");
|
|
510
|
+
vi.spyOn(AuthenticationManager, "loginNPM");
|
|
511
|
+
vi.spyOn(AuthenticationManager, "loginSPM");
|
|
512
|
+
vi.mocked(getRepositoryEndpoint).mockResolvedValue("http://repositoryEndpoint.com");
|
|
513
|
+
vi.stubGlobal("JSON", {
|
|
514
|
+
parse: vi.fn().mockReturnValue({ registries: {}, authentication: {} }),
|
|
515
|
+
stringify: JSON.stringify,
|
|
516
|
+
});
|
|
517
|
+
vi.useFakeTimers();
|
|
518
|
+
});
|
|
519
|
+
|
|
520
|
+
afterEach(() => {
|
|
521
|
+
vi.restoreAllMocks();
|
|
522
|
+
vi.useRealTimers();
|
|
523
|
+
vi.unstubAllGlobals();
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
it("should throw if unable to get codeartifact token", async () => {
|
|
527
|
+
sendMock.mockReturnValueOnce({ authorizationToken: null, expiration: null });
|
|
528
|
+
return expect(AuthenticationManager.loginCodeArtifact("org", awsCreds)).rejects.toThrow(
|
|
529
|
+
"Authorization token not found",
|
|
530
|
+
);
|
|
531
|
+
});
|
|
532
|
+
|
|
533
|
+
it("should update codeartifact token", async () => {
|
|
534
|
+
sendMock.mockReturnValueOnce({ authorizationToken: "authorizationToken", expiration: new Date() });
|
|
535
|
+
await AuthenticationManager.loginCodeArtifact("org", awsCreds);
|
|
536
|
+
expect(vi.mocked(CredentialsHelper.updateCodeArtifactToken)).toHaveBeenCalledExactlyOnceWith("org", {
|
|
537
|
+
expiration: new Date(),
|
|
538
|
+
token: "authorizationToken",
|
|
539
|
+
});
|
|
540
|
+
expect(AuthenticationManager.loginNPM).toHaveBeenCalledExactlyOnceWith("org", awsCreds, {
|
|
541
|
+
expiration: new Date(),
|
|
542
|
+
token: "authorizationToken",
|
|
543
|
+
});
|
|
544
|
+
expect(AuthenticationManager.loginGradle).toHaveBeenCalledExactlyOnceWith("org", {
|
|
545
|
+
expiration: new Date(),
|
|
546
|
+
token: "authorizationToken",
|
|
547
|
+
});
|
|
548
|
+
});
|
|
549
|
+
it("should update codeartifact token and call loginSPM on darwin", async () => {
|
|
550
|
+
Object.defineProperty(process, "platform", { value: "darwin" });
|
|
551
|
+
|
|
552
|
+
sendMock.mockReturnValueOnce({ authorizationToken: "authorizationToken", expiration: new Date() });
|
|
553
|
+
await AuthenticationManager.loginCodeArtifact("org", awsCreds);
|
|
554
|
+
|
|
555
|
+
expect(AuthenticationManager.loginSPM).toHaveBeenCalledExactlyOnceWith("org", awsCreds, {
|
|
556
|
+
expiration: new Date(),
|
|
557
|
+
token: "authorizationToken",
|
|
558
|
+
});
|
|
559
|
+
});
|
|
560
|
+
|
|
561
|
+
it("should update codeartifact token and not call loginSPM on non-darwin platforms", async () => {
|
|
562
|
+
Object.defineProperty(process, "platform", { value: "linux" });
|
|
563
|
+
|
|
564
|
+
sendMock.mockReturnValueOnce({ authorizationToken: "authorizationToken", expiration: new Date() });
|
|
565
|
+
await AuthenticationManager.loginCodeArtifact("org", awsCreds);
|
|
566
|
+
|
|
567
|
+
expect(AuthenticationManager.loginSPM).not.toHaveBeenCalled();
|
|
568
|
+
});
|
|
569
|
+
});
|
|
570
|
+
|
|
571
|
+
describe("loginNPM", () => {
|
|
572
|
+
beforeEach(() => {
|
|
573
|
+
vi.useFakeTimers({ now: 0 });
|
|
574
|
+
});
|
|
575
|
+
|
|
576
|
+
afterEach(() => {
|
|
577
|
+
vi.useRealTimers();
|
|
578
|
+
});
|
|
579
|
+
|
|
580
|
+
it("should login to npm codeartifact", async () => {
|
|
581
|
+
vi.mocked(createCodeArtifactClient).mockReturnValueOnce({
|
|
582
|
+
send: vi.fn(() => {
|
|
583
|
+
return Promise.resolve({
|
|
584
|
+
authorizationToken: "token",
|
|
585
|
+
expiration: new Date(),
|
|
586
|
+
});
|
|
587
|
+
}),
|
|
588
|
+
} as unknown as CodeartifactClient);
|
|
589
|
+
vi.mocked(getRepositoryEndpoint).mockResolvedValueOnce("https://example.com");
|
|
590
|
+
await AuthenticationManager.loginNPM(
|
|
591
|
+
"org",
|
|
592
|
+
{
|
|
593
|
+
accessKeyId: "accessKeyId",
|
|
594
|
+
expiration: "expiration",
|
|
595
|
+
identityId: "identityId",
|
|
596
|
+
secretAccessKey: "secretAccessKey",
|
|
597
|
+
sessionToken: "sessionToken",
|
|
598
|
+
},
|
|
599
|
+
{ token: "token", expiration: new Date() },
|
|
600
|
+
);
|
|
601
|
+
|
|
602
|
+
// Check npm config setup
|
|
603
|
+
expect(execSync).toBeCalledTimes(2);
|
|
604
|
+
expect(vi.mocked(execSync).mock.calls[0][0]).toEqual("npm config set @dana:registry=https://example.com");
|
|
605
|
+
expect(vi.mocked(execSync).mock.calls[1][0]).toEqual("npm config set //example.com:_authToken=token");
|
|
606
|
+
});
|
|
607
|
+
|
|
608
|
+
it("should throw if cannot get CodeArtifact endpoint", () => {
|
|
609
|
+
vi.mocked(createCodeArtifactClient).mockReturnValueOnce({
|
|
610
|
+
send: vi.fn(() => {
|
|
611
|
+
return Promise.resolve({
|
|
612
|
+
authorizationToken: "token",
|
|
613
|
+
expiration: new Date(),
|
|
614
|
+
});
|
|
615
|
+
}),
|
|
616
|
+
} as unknown as CodeartifactClient);
|
|
617
|
+
vi.mocked(getRepositoryEndpoint).mockRejectedValueOnce(new Error("ENDPOINT"));
|
|
618
|
+
|
|
619
|
+
return expect(() =>
|
|
620
|
+
AuthenticationManager.loginNPM(
|
|
621
|
+
"org",
|
|
622
|
+
{
|
|
623
|
+
accessKeyId: "accessKeyId",
|
|
624
|
+
expiration: "expiration",
|
|
625
|
+
identityId: "identityId",
|
|
626
|
+
secretAccessKey: "secretAccessKey",
|
|
627
|
+
sessionToken: "sessionToken",
|
|
628
|
+
},
|
|
629
|
+
{ token: "token", expiration: new Date() },
|
|
630
|
+
),
|
|
631
|
+
).rejects.toThrow("ENDPOINT");
|
|
632
|
+
});
|
|
633
|
+
});
|
|
634
|
+
|
|
635
|
+
describe("loginGradle", () => {
|
|
636
|
+
beforeEach(() => {
|
|
637
|
+
vi.useFakeTimers({ now: 0 });
|
|
638
|
+
vi.mocked(createCodeArtifactClient).mockReturnValueOnce({
|
|
639
|
+
send: vi.fn(() => {
|
|
640
|
+
return Promise.resolve({
|
|
641
|
+
authorizationToken: "token",
|
|
642
|
+
expiration: new Date(),
|
|
643
|
+
});
|
|
644
|
+
}),
|
|
645
|
+
} as unknown as CodeartifactClient);
|
|
646
|
+
|
|
647
|
+
vol.fromJSON({});
|
|
648
|
+
vi.mocked(formatRepositoryString).mockReturnValue("https://repository.com");
|
|
649
|
+
});
|
|
650
|
+
|
|
651
|
+
afterEach(() => {
|
|
652
|
+
vi.useRealTimers();
|
|
653
|
+
});
|
|
654
|
+
|
|
655
|
+
it("should create ~/.gradle directory and gradle.properties file if not exist", async () => {
|
|
656
|
+
await AuthenticationManager.loginGradle("org", {
|
|
657
|
+
token: "token",
|
|
658
|
+
expiration: new Date(),
|
|
659
|
+
});
|
|
660
|
+
|
|
661
|
+
const gradleProperties = vol.readFileSync("/HOME/.gradle/gradle.properties", "utf-8");
|
|
662
|
+
expect(gradleProperties).toContain("dana.https://repository.com.token=token");
|
|
663
|
+
});
|
|
664
|
+
|
|
665
|
+
it("should update existing property from gradle.properties file", async () => {
|
|
666
|
+
vol.fromJSON({
|
|
667
|
+
["/HOME/.gradle/gradle.properties"]: "dana.https://repository.com.token=somevalue\n",
|
|
668
|
+
});
|
|
669
|
+
await AuthenticationManager.loginGradle("org", {
|
|
670
|
+
token: "token",
|
|
671
|
+
expiration: new Date(),
|
|
672
|
+
});
|
|
673
|
+
const gradleProperties = vol.readFileSync("/HOME/.gradle/gradle.properties", "utf-8");
|
|
674
|
+
expect(gradleProperties).toContain("dana.https://repository.com.token=token\n");
|
|
675
|
+
});
|
|
676
|
+
|
|
677
|
+
it("should add property to gradle.properties file", async () => {
|
|
678
|
+
vol.fromJSON({
|
|
679
|
+
["/HOME/.gradle/gradle.properties"]: "",
|
|
680
|
+
});
|
|
681
|
+
await AuthenticationManager.loginGradle("org", {
|
|
682
|
+
token: "token",
|
|
683
|
+
expiration: new Date(),
|
|
684
|
+
});
|
|
685
|
+
const gradleProperties = vol.readFileSync("/HOME/.gradle/gradle.properties", "utf-8");
|
|
686
|
+
expect(gradleProperties).toContain("dana.https://repository.com.token=token\n");
|
|
687
|
+
});
|
|
688
|
+
});
|
|
689
|
+
|
|
690
|
+
describe("loginSPM", () => {
|
|
691
|
+
beforeEach(() => {
|
|
692
|
+
vi.mocked(ensureSPMDirectoriesExists).mockResolvedValue("filePath");
|
|
693
|
+
vi.mocked(createCodeArtifactClient).mockReturnValueOnce({
|
|
694
|
+
send: vi.fn(() => {
|
|
695
|
+
return Promise.resolve({
|
|
696
|
+
authorizationToken: "token",
|
|
697
|
+
expiration: new Date(),
|
|
698
|
+
});
|
|
699
|
+
}),
|
|
700
|
+
} as unknown as CodeartifactClient);
|
|
701
|
+
vi.mocked(getRepositoryEndpoint).mockResolvedValueOnce("https://example.com");
|
|
702
|
+
});
|
|
703
|
+
|
|
704
|
+
it("should call ensureSPMDirectoriesExists", async () => {
|
|
705
|
+
await AuthenticationManager.loginSPM(
|
|
706
|
+
"org",
|
|
707
|
+
{
|
|
708
|
+
accessKeyId: "accessKeyId",
|
|
709
|
+
expiration: "expiration",
|
|
710
|
+
identityId: "identityId",
|
|
711
|
+
secretAccessKey: "secretAccessKey",
|
|
712
|
+
sessionToken: "sessionToken",
|
|
713
|
+
},
|
|
714
|
+
{ token: "token", expiration: new Date() },
|
|
715
|
+
);
|
|
716
|
+
|
|
717
|
+
expect(vi.mocked(ensureSPMDirectoriesExists)).toHaveBeenCalledExactlyOnceWith();
|
|
718
|
+
});
|
|
719
|
+
|
|
720
|
+
it("should call updateSPMRegistries", async () => {
|
|
721
|
+
await AuthenticationManager.loginSPM(
|
|
722
|
+
"org",
|
|
723
|
+
{
|
|
724
|
+
accessKeyId: "accessKeyId",
|
|
725
|
+
expiration: "expiration",
|
|
726
|
+
identityId: "identityId",
|
|
727
|
+
secretAccessKey: "secretAccessKey",
|
|
728
|
+
sessionToken: "sessionToken",
|
|
729
|
+
},
|
|
730
|
+
{ token: "token", expiration: new Date() },
|
|
731
|
+
);
|
|
732
|
+
await ensureSPMDirectoriesExists();
|
|
733
|
+
expect(vi.mocked(updateSPMRegistries)).toHaveBeenCalledExactlyOnceWith(
|
|
734
|
+
"filePath",
|
|
735
|
+
"dana",
|
|
736
|
+
"https://example.com",
|
|
737
|
+
);
|
|
738
|
+
});
|
|
739
|
+
|
|
740
|
+
it("should call updateSPMToken", async () => {
|
|
741
|
+
await AuthenticationManager.loginSPM(
|
|
742
|
+
"org",
|
|
743
|
+
{
|
|
744
|
+
accessKeyId: "accessKeyId",
|
|
745
|
+
expiration: "expiration",
|
|
746
|
+
identityId: "identityId",
|
|
747
|
+
secretAccessKey: "secretAccessKey",
|
|
748
|
+
sessionToken: "sessionToken",
|
|
749
|
+
},
|
|
750
|
+
{ token: "token", expiration: new Date() },
|
|
751
|
+
);
|
|
752
|
+
|
|
753
|
+
expect(vi.mocked(updateSPMToken)).toHaveBeenCalledExactlyOnceWith("https://example.com", "token");
|
|
754
|
+
});
|
|
755
|
+
});
|
|
756
|
+
});
|