Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
Merge pull request #3604 from southworks/feature/southworks/botskills…
Browse files Browse the repository at this point in the history
…-sanitize-appsettings

[Botskills] Sanitize appSettings properties for all the commands
  • Loading branch information
peterinnesmsft committed Oct 5, 2020
2 parents 6a8758c + c676b48 commit 15688d2
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 12 deletions.
4 changes: 2 additions & 2 deletions tools/botskills/src/functionality/connectSkill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
ISkill,
IModel
} from '../models';
import { ChildProcessUtils, getDispatchNames, isValidCultures, wrapPathWithQuotes, isCloudGovernment, ManifestUtils, libraries, validateLibrary } from '../utils';
import { ChildProcessUtils, getDispatchNames, isValidCultures, wrapPathWithQuotes, isCloudGovernment, ManifestUtils, libraries, validateLibrary, sanitizeAppSettingsProperties } from '../utils';
import { RefreshSkill } from './refreshSkill';
import { IManifest } from '../models/manifest';

Expand Down Expand Up @@ -340,7 +340,7 @@ Make sure you have a Dispatch for the cultures you are trying to connect, and th
private async connectSkillManifest(cognitiveModelsFile: ICognitiveModel, skillManifest: IManifest): Promise<void> {
try {
// Take VA Skills configurations
const assistantSkillsFile: IAppSetting = JSON.parse(readFileSync(this.configuration.appSettingsFile, 'UTF8'));
const assistantSkillsFile: IAppSetting = JSON.parse(sanitizeAppSettingsProperties(this.configuration.appSettingsFile));
const assistantSkills: ISkill[] = assistantSkillsFile.botFrameworkSkills !== undefined ? assistantSkillsFile.botFrameworkSkills : [];

// Check if the skill is already connected to the assistant
Expand Down
4 changes: 2 additions & 2 deletions tools/botskills/src/functionality/disconnectSkill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
IAppSetting,
ISkill
} from '../models';
import { getDispatchNames } from '../utils';
import { getDispatchNames, sanitizeAppSettingsProperties } from '../utils';

export class DisconnectSkill {
private readonly configuration: IDisconnectConfiguration;
Expand Down Expand Up @@ -97,7 +97,7 @@ Please make sure to provide a valid path to your Assistant Skills configuration
}

// Take VA Skills configurations
const assistantSkillsFile: IAppSetting = JSON.parse(readFileSync(this.configuration.appSettingsFile, 'UTF8'));
const assistantSkillsFile: IAppSetting = JSON.parse(sanitizeAppSettingsProperties(this.configuration.appSettingsFile));
const assistantSkills: ISkill[] = assistantSkillsFile.botFrameworkSkills !== undefined ? assistantSkillsFile.botFrameworkSkills : [];

// Check if the skill is present in the assistant
Expand Down
3 changes: 1 addition & 2 deletions tools/botskills/src/functionality/listSkill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ Please make sure to provide a valid path to your Assistant Skills configuration

return false;
}
// Take VA Skills configurations
// Take VA Skills configurations
const assistantAppSettingsFile: IAppSetting = JSON.parse(sanitizeAppSettingsProperties(configuration.appSettingsFile));

if (assistantAppSettingsFile.botFrameworkSkills === undefined) {
this.logger.message('There are no Skills connected to the assistant.');

Expand Down
3 changes: 2 additions & 1 deletion tools/botskills/src/functionality/migrateSkill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { existsSync, readFileSync, writeFileSync } from 'fs';
import { ConsoleLogger, ILogger} from '../logger';
import { IMigrateConfiguration, IAppSetting, ISkill, ISkillFileV1 } from '../models';
import { manifestV1Validation } from '../utils/validationUtils';
import { sanitizeAppSettingsProperties } from '../utils';

export class MigrateSkill {
public logger: ILogger;
Expand Down Expand Up @@ -39,7 +40,7 @@ Please make sure to provide a valid path to your Assistant Skills configuration
return false;
}

const destFile: IAppSetting = JSON.parse(readFileSync(configuration.destFile, 'UTF8'));
const destFile: IAppSetting = JSON.parse(sanitizeAppSettingsProperties(configuration.destFile));

const destAssistantSkills: ISkill[] = destFile.botFrameworkSkills || [];

Expand Down
5 changes: 2 additions & 3 deletions tools/botskills/src/functionality/updateSkill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
* Licensed under the MIT License.
*/

import { readFileSync } from 'fs';
import { ConsoleLogger, ILogger } from '../logger';
import { IConnectConfiguration, IDisconnectConfiguration, ISkillManifestV2, ISkillManifestV1, IUpdateConfiguration, ISkill, IAppSetting } from '../models';
import { ConnectSkill } from './connectSkill';
import { DisconnectSkill } from './disconnectSkill';
import { ManifestUtils } from '../utils';
import { ManifestUtils, sanitizeAppSettingsProperties } from '../utils';
import { IManifest } from '../models/manifest';

export class UpdateSkill {
Expand All @@ -28,7 +27,7 @@ export class UpdateSkill {
const rawManifest: string = await this.manifestUtils.getRawManifestFromResource(this.configuration);
const skillManifest: IManifest = await this.manifestUtils.getManifest(rawManifest, this.logger);

const assistantSkillsFile: IAppSetting = JSON.parse(readFileSync(this.configuration.appSettingsFile, 'UTF8'));
const assistantSkillsFile: IAppSetting = JSON.parse(sanitizeAppSettingsProperties(this.configuration.appSettingsFile));
const assistantSkills: ISkill[] = assistantSkillsFile.botFrameworkSkills !== undefined ? assistantSkillsFile.botFrameworkSkills : [];
// Check if the skill is already connected to the assistant
if (assistantSkills.find((assistantSkill: ISkill): boolean => assistantSkill.id === skillManifest.id)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"microsoftAppId": "",
"microsoftAppPassword": "",
"appInsights": {
"appId": "",
"instrumentationKey": ""
},
"blobStorage": {
"connectionString": "",
"container": ""
},
"cosmosDb": {
"authkey": "",
"collectionId": "",
"cosmosDBEndpoint": "",
"databaseId": ""
},
"contentModerator": {
"key": ""
},
"BotFrameworkSkills": [
{
"Id": "testSkill",
"AppId": "",
"SkillEndpoint": "",
"Name": "",
"Description": ""
}
]
}
18 changes: 16 additions & 2 deletions tools/botskills/test/sanitization.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
* Licensed under the MIT License.
*/

const { strictEqual } = require("assert");
const { sanitizePath } = require("../lib/utils");
const { strictEqual, ok } = require("assert");
const { sanitizePath, sanitizeAppSettingsProperties } = require("../lib/utils");
const { join } = require("path");

describe("The sanitization path util", function () {
describe("should return a path without trailing backslash", function () {
Expand All @@ -18,4 +19,17 @@ describe("The sanitization path util", function () {
strictEqual(sanitizePath(path), path.substring(0, path.length - 1));
});
})

describe("should return an appSettingsFile with the BotFrameworkSkills property and its values with the first letter in lowercase", function () {
it("when the first letter of the BotFrameworkSkills property and its values are in uppercase", async function() {
const pathToAppSettingsFile = join(__dirname, "mocks", "appsettings", "appsettingsWithUppercase.json");
const appSettings = JSON.parse(sanitizeAppSettingsProperties(pathToAppSettingsFile));
ok('botFrameworkSkills' in appSettings);
ok('id' in appSettings.botFrameworkSkills[0]);
ok('name' in appSettings.botFrameworkSkills[0]);
ok('appId' in appSettings.botFrameworkSkills[0]);
ok('description' in appSettings.botFrameworkSkills[0]);
ok('skillEndpoint' in appSettings.botFrameworkSkills[0]);
});
})
})

0 comments on commit 15688d2

Please sign in to comment.