Skip to content

Commit

Permalink
fix: Move skill settings into settings.skillConfiguration (#4312)
Browse files Browse the repository at this point in the history
  • Loading branch information
srinaath authored Oct 1, 2020
1 parent c5e31b6 commit 2011ccd
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

import set from 'lodash/set';
import { SensitiveProperties } from '@bfc/shared';
import { DialogSetting, SensitiveProperties } from '@bfc/shared';
import { UserIdentity } from '@bfc/extension';

import { Path } from '../../utility/path';
Expand All @@ -16,7 +16,7 @@ export class DefaultSettingManager extends FileSettingManager {
super(basePath, user);
}

protected createDefaultSettings = (): any => {
protected createDefaultSettings = (): DialogSetting => {
return {
feature: {
UseShowTypingMiddleware: false,
Expand Down Expand Up @@ -69,10 +69,11 @@ export class DefaultSettingManager extends FileSettingManager {
maxImbalanceRatio: 10,
maxUtteranceAllowed: 15000,
},
skill: {
skillConfiguration: {
isSkill: false,
allowedCallers: ['*'],
},
skill: {},
defaultLanguage: 'en-us',
languages: ['en-us'],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public class AllowedCallersClaimsValidator : ClaimsValidator
{
private readonly List<string> _allowedCallers;

public AllowedCallersClaimsValidator(BotSkillSettings settings)
public AllowedCallersClaimsValidator(BotSkillConfiguration settings)
{
// skill.allowedCallers is the setting in the appsettings.json file
// skillConfiguration.allowedCallers is the setting in the appsettings.json file
// that consists of the list of parent bot IDs that are allowed to access the skill.
// To add a new parent bot, simply edit the AllowedCallers and add
// the parent bot's Microsoft app ID to the list.
Expand Down
8 changes: 6 additions & 2 deletions runtime/dotnet/azurewebapp/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public IStorage ConfigureStorage(BotSettings settings)

public bool IsSkill(BotSettings settings)
{
return settings?.Skill?.IsSkill == true;
return settings?.SkillConfiguration?.IsSkill == true;
}

public BotFrameworkHttpAdapter GetBotAdapter(IStorage storage, BotSettings settings, UserState userState, ConversationState conversationState, IServiceProvider s, TelemetryInitializerMiddleware telemetryInitializerMiddleware)
Expand Down Expand Up @@ -132,7 +132,11 @@ public void ConfigureServices(IServiceCollection services)
// Register AuthConfiguration to enable custom claim validation for skills.
if (IsSkill(settings))
{
services.AddSingleton(sp => new AuthenticationConfiguration { ClaimsValidator = new AllowedCallersClaimsValidator(settings.Skill) });
services.AddSingleton(sp => new AuthenticationConfiguration { ClaimsValidator = new AllowedCallersClaimsValidator(settings.SkillConfiguration) });
}
else
{
services.AddSingleton(sp => new AuthenticationConfiguration());
}

// register components.
Expand Down
2 changes: 1 addition & 1 deletion runtime/dotnet/core/Settings/BotSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class BotSettings

public string Bot { get; set; }

public BotSkillSettings Skill { get; set; }
public BotSkillConfiguration SkillConfiguration { get; set; }

public class BlobStorageConfiguration
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Microsoft.BotFramework.Composer.Core.Settings
{
public class BotSkillSettings
public class BotSkillConfiguration
{
// Is skill
public bool IsSkill { get; set; }
Expand Down
12 changes: 6 additions & 6 deletions runtime/dotnet/tests/AllowedCallersClaimsValidationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ public class AllowedCallersClaimsValidationTests
[ExpectedException(typeof(ArgumentException))]
public void WhenAllowedCallersIsNullThrowException()
{
var unused = new AllowedCallersClaimsValidator(new BotSkillSettings());
var unused = new AllowedCallersClaimsValidator(new BotSkillConfiguration());
}

[TestMethod]
[ExpectedException(typeof(ArgumentException))]
public void WhenAllowedCallersIsEmptyThrowException()
{
var unused = new AllowedCallersClaimsValidator(new BotSkillSettings()
var unused = new AllowedCallersClaimsValidator(new BotSkillConfiguration()
{
AllowedCallers = new string[0]
});
Expand All @@ -35,7 +35,7 @@ public void WhenAllowedCallersIsEmptyThrowException()
[TestMethod]
public async Task AllowAnyCaller()
{
var validator = new AllowedCallersClaimsValidator(new BotSkillSettings()
var validator = new AllowedCallersClaimsValidator(new BotSkillConfiguration()
{
AllowedCallers = new string[]{"*"}
});
Expand All @@ -49,7 +49,7 @@ public async Task AllowAnyCaller()
public async Task AllowedCaller()
{
const string callerAppId = "BE3F9920-D42D-4D3A-9BDF-DBA62DAE3A00";
var validator = new AllowedCallersClaimsValidator(new BotSkillSettings()
var validator = new AllowedCallersClaimsValidator(new BotSkillConfiguration()
{
AllowedCallers = new string[]{callerAppId}
});
Expand All @@ -63,7 +63,7 @@ public async Task AllowedCaller()
public async Task AllowedCallers()
{
const string callerAppId = "BE3F9920-D42D-4D3A-9BDF-DBA62DAE3A00";
var validator = new AllowedCallersClaimsValidator(new BotSkillSettings()
var validator = new AllowedCallersClaimsValidator(new BotSkillConfiguration()
{
AllowedCallers = new string[]{"anotherId", callerAppId}
});
Expand All @@ -78,7 +78,7 @@ public async Task AllowedCallers()
public async Task NonAllowedCallerShouldThrowException()
{
var callerAppId = "BE3F9920-D42D-4D3A-9BDF-DBA62DAE3A00";
var validator = new AllowedCallersClaimsValidator(new BotSkillSettings()
var validator = new AllowedCallersClaimsValidator(new BotSkillConfiguration()
{
AllowedCallers = new string[]{callerAppId}
});
Expand Down

0 comments on commit 2011ccd

Please sign in to comment.