Skip to content

Commit eda06a3

Browse files
committed
Enhance security authentication configuration with authprovider api
1 parent a98cf07 commit eda06a3

11 files changed

Lines changed: 144 additions & 174 deletions

File tree

src/plugins/auth-providers/authentication-service/index.ts

Lines changed: 0 additions & 91 deletions
This file was deleted.

src/plugins/auth-providers/authentication-service/schema.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/plugins/auth-providers/disable.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
"authProviders": {
55
"TestAuthProvider": {
66
"consumerSecret": "test-secret-12345",
7-
"consumerKey": "test-key-67890",
8-
"enableAuthenticationService": false
7+
"consumerKey": "test-key-67890"
98
}
109
}
1110
}

src/plugins/auth-providers/enable.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
"authProviders": {
55
"TestAuthProvider": {
66
"consumerSecret": "test-secret-12345",
7-
"consumerKey": "test-key-67890",
8-
"enableAuthenticationService": true
7+
"consumerKey": "test-key-67890"
98
}
109
}
1110
}

src/plugins/auth-providers/index.e2e-spec.ts

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -37,26 +37,6 @@ describe(AuthProviders.name, function () {
3737
TestAuthProvider: {},
3838
};
3939

40-
const configWithAuthenticationService: Config = {
41-
TestAuthProvider: {
42-
enableAuthenticationService: true,
43-
},
44-
};
45-
46-
const configWithDisabledAuthenticationService: Config = {
47-
TestAuthProvider: {
48-
enableAuthenticationService: false,
49-
},
50-
};
51-
52-
const configWithAllProperties: Config = {
53-
TestAuthProvider: {
54-
consumerSecret: 'test-secret-12345',
55-
consumerKey: 'test-key-67890',
56-
enableAuthenticationService: true,
57-
},
58-
};
59-
6040
it('should deploy an AuthProvider for testing', () => {
6141
const sourceDeployCmd = child.spawnSync('sf', [
6242
'project',
@@ -86,16 +66,6 @@ describe(AuthProviders.name, function () {
8666
await plugin.apply(configEmpty);
8767
});
8868

89-
it('should enable authentication service', async () => {
90-
await plugin.apply(configWithAuthenticationService);
91-
// Note: retrieve() returns empty config, so we can only verify apply completes without errors
92-
});
93-
94-
it('should update consumerSecret, consumerKey, and enable authentication service together', async () => {
95-
await plugin.apply(configWithAllProperties);
96-
// Note: retrieve() returns empty config, so we can only verify apply completes without errors
97-
});
98-
9969
it('should throw an error when AuthProvider does not exist', async () => {
10070
const configInvalid: Config = {
10171
NonExistentAuthProvider: {
@@ -114,11 +84,6 @@ describe(AuthProviders.name, function () {
11484
}, /No AuthProviders found with DeveloperNames/);
11585
});
11686

117-
it('should disable authentication service', async () => {
118-
await plugin.apply(configWithDisabledAuthenticationService);
119-
// Note: retrieve() returns empty config, so we can only verify apply completes without errors
120-
});
121-
12287
it('should remove the testing AuthProvider', async () => {
12388
await global.browserforce.connection.metadata.delete('AuthProvider', ['TestAuthProvider']);
12489
});

src/plugins/auth-providers/index.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { type SalesforceUrlPath, waitForPageErrors } from '../../browserforce.js';
22
import { BrowserforcePlugin } from '../../plugin.js';
3-
import { AuthenticationService } from './authentication-service/index.js';
43

54
const CONSUMER_SECRET_SELECTOR = '#ConsumerSecret';
65
const CONSUMER_KEY_SELECTOR = '#ConsumerKey';
@@ -11,7 +10,6 @@ const getUrl = (orgId: string): SalesforceUrlPath => `/${orgId}/e` as Salesforce
1110
type AuthProviderConfig = {
1211
consumerSecret?: string;
1312
consumerKey?: string;
14-
enableAuthenticationService?: boolean;
1513
};
1614

1715
export type Config = {
@@ -76,8 +74,7 @@ export class AuthProviders extends BrowserforcePlugin {
7674
// Navigate to the edit page
7775
const editPageUrl = getUrl(authProviderId);
7876

79-
this.browserforce.logger?.log('editPageUrl', editPageUrl);
80-
console.log(`[AuthProviders] Navigating to edit page for ${developerName}: ${editPageUrl}`);
77+
this.browserforce.logger?.log(`Navigating to edit page for ${developerName}: ${editPageUrl}`);
8178

8279
await using page = await this.browserforce.openPage(editPageUrl);
8380

@@ -132,16 +129,6 @@ export class AuthProviders extends BrowserforcePlugin {
132129
await waitForPageErrors(page);
133130
}
134131
}
135-
136-
// Handle enableAuthenticationService if requested
137-
if (authProviderConfig.enableAuthenticationService !== undefined) {
138-
const pluginAuthenticationService = new AuthenticationService(this.browserforce);
139-
await pluginAuthenticationService.apply({
140-
authProviderId,
141-
developerName,
142-
enabled: authProviderConfig.enableAuthenticationService,
143-
});
144-
}
145132
} catch (error) {
146133
throw new Error(`Failed to update AuthProvider '${developerName}': ${error.message}`);
147134
}

src/plugins/auth-providers/schema.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
"title": "Consumer Key",
1919
"description": "The Consumer Key value for the Auth Provider",
2020
"type": "string"
21-
},
22-
"enableAuthenticationService": {
23-
"$ref": "./authentication-service/schema.json"
2421
}
2522
}
2623
}

src/plugins/security/authentication-configuration/disable.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"services": [
77
{
88
"label": "Login Form",
9-
"enabled": false
9+
"enabled": true
1010
}
1111
]
1212
}

src/plugins/security/authentication-configuration/index.e2e-spec.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ describe(AuthenticationConfiguration.name, function () {
3535
{ label: 'TestAuthMethod', enabled: false },
3636
],
3737
};
38+
const configRetrieveByApiName: Config = {
39+
services: [{ authProviderApiName: 'TestAuthMethod', enabled: true }],
40+
};
41+
const configApplyByApiName: Config = {
42+
services: [
43+
{ label: 'Login Form', enabled: true },
44+
{ authProviderApiName: 'TestAuthMethod', enabled: false },
45+
],
46+
};
47+
const configApplyMissingApiName: Config = {
48+
services: [{ authProviderApiName: 'NonExistentAuthProvider', enabled: true }],
49+
};
3850

3951
it('should retrieve the single enabled Login Form auth', async () => {
4052
const res = await plugin.retrieve(configRetrieveSingle);
@@ -76,6 +88,34 @@ describe(AuthenticationConfiguration.name, function () {
7688
assert.deepStrictEqual(res, configApplyMultiple);
7789
});
7890

91+
it('should retrieve using authProviderApiName', async () => {
92+
const res = await plugin.retrieve(configRetrieveByApiName);
93+
assert.deepStrictEqual(res, configRetrieveByApiName);
94+
});
95+
96+
it('should update auth service using authProviderApiName', async () => {
97+
await plugin.apply(configApplyByApiName);
98+
const res = await plugin.retrieve(configApplyByApiName);
99+
assert.deepStrictEqual(res, configApplyByApiName);
100+
});
101+
102+
it('should not do anything when run with authProviderApiName and config already set', async () => {
103+
const res = await plugin.run(configApplyByApiName);
104+
assert.deepStrictEqual(res, { message: 'no action necessary' });
105+
});
106+
107+
it('should throw an error when authProviderApiName does not exist', async () => {
108+
let err;
109+
try {
110+
await plugin.apply(configApplyMissingApiName);
111+
} catch (e) {
112+
err = e;
113+
}
114+
assert.throws(() => {
115+
throw err;
116+
}, /not found/);
117+
});
118+
79119
it('should throw an error when trying to apply a missing service', async () => {
80120
let err;
81121
try {

0 commit comments

Comments
 (0)