UNPKG

@mindconnect/mindconnect-nodejs

Version:

NodeJS Library for Siemens Insights Hub Connectivity - TypeScript SDK for Insights Hub and Industrial IoT - Command Line Interface - Insights Hub Development Proxy (Siemens Insights Hub was formerly known as MindSphere)

73 lines 4.46 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); // Copyright (C), Siemens AG 2017 const chai = require("chai"); const debug = require("debug"); const mocha_1 = require("mocha"); require("url-search-params-polyfill"); const src_1 = require("../src"); const credential_auth_1 = require("../src/api/credential-auth"); const mindconnect_base_1 = require("../src/api/mindconnect-base"); const sdk_1 = require("../src/api/sdk"); const tokenmanager_auth_1 = require("../src/api/tokenmanager-auth"); const utils_1 = require("../src/api/utils"); const test_agent_setup_utils_1 = require("./test-agent-setup-utils"); const test_utils_1 = require("./test-utils"); const log = debug("mindconnect-agent-test"); chai.should(); describe("[SDK] using agent authorization", () => { const auth = (0, utils_1.loadAuth)(); const sdk = new sdk_1.MindSphereSdk(Object.assign(Object.assign({}, auth), { basicAuth: (0, utils_1.decrypt)(auth, (0, test_utils_1.getPasskeyForUnitTest)()) })); let agentConfig = {}; let unitTestConfiguration = {}; before(() => __awaiter(void 0, void 0, void 0, function* () { unitTestConfiguration = yield (0, test_agent_setup_utils_1.unitTestSetup)(sdk, sdk_1.AgentManagementModels.AgentUpdate.SecurityProfileEnum.SHAREDSECRET); agentConfig = unitTestConfiguration.agentConfig; })); after(() => __awaiter(void 0, void 0, void 0, function* () { yield (0, test_agent_setup_utils_1.tearDownAgents)(sdk, unitTestConfiguration); })); (0, mocha_1.it)("should instantiate shared secret agent.", () => { const agent = new src_1.MindConnectAgent(agentConfig); agent.should.not.be.null; agent._configuration.should.not.be.null; agent._configuration.content.clientCredentialProfile[0].should.be.equal("SHARED_SECRET"); agent._storage.should.not.be.null; }); (0, mocha_1.it)("should be able to run the SDK with agent authorization", () => __awaiter(void 0, void 0, void 0, function* () { var _a, _b; const agent = new src_1.MindConnectAgent(agentConfig); if (!agent.IsOnBoarded()) { yield agent.OnBoard(); agent._configuration.response.should.not.be.null; } else { log("The agent is already onboarded"); } const mysdk = new sdk_1.MindSphereSdk(agent); const assetManagement = mysdk.GetAssetManagementClient(); (yield assetManagement.GetToken()).should.not.be.undefined; (_b = (_a = (yield assetManagement.GetAssets())._embedded) === null || _a === void 0 ? void 0 : _a.assets) === null || _b === void 0 ? void 0 : _b.length.should.be.greaterThan(0); })); (0, mocha_1.it)("should determine if something implements TokenRotation", () => __awaiter(void 0, void 0, void 0, function* () { const agent = new src_1.MindConnectAgent(agentConfig); const credentialAuth = new credential_auth_1.CredentialAuth("https://developer.siemens.com", "Basic: test", "test"); const tokenManagerAuth = new tokenmanager_auth_1.TokenManagerAuth("https://developer.siemens.com", "Basic: test", "test", "test", "test", "test"); (0, mindconnect_base_1.isTokenRotation)({ GetToken: "", GetTenant: "", GetGateway: "", RenewToken: "" }).should.be.false; (0, mindconnect_base_1.isTokenRotation)({ GetToken: () => { }, GetTenant: () => { }, GetGateway: () => { }, RenewToken: () => { } }).should .be.true; (0, mindconnect_base_1.isTokenRotation)(agent).should.be.true; (0, mindconnect_base_1.isTokenRotation)(credentialAuth).should.be.true; (0, mindconnect_base_1.isTokenRotation)(tokenManagerAuth).should.be.true; })); }); //# sourceMappingURL=sdk-with-agent-auth.spec.js.map