Skip to content

Commit

Permalink
Merge pull request #48 from stormpath/fix-defaults-password-and-verif…
Browse files Browse the repository at this point in the history
…ication

Allow user-provided config to disable email verification, password reset
  • Loading branch information
typerandom committed May 9, 2016
2 parents 0035ae3 + 67e895f commit 3db8b28
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 15 deletions.
7 changes: 4 additions & 3 deletions lib/strategy/EnrichIntegrationFromRemoteConfigStrategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,19 @@ EnrichIntegrationFromRemoteConfigStrategy.prototype._enrichWithDirectoryPolicies
// Enrich config with with directory policies.
client.getDirectory(directoryHref, { expand: 'passwordPolicy,accountCreationPolicy' }, stopIfError(function (directory) {
var resetEmailStatusEnabled = isEnabled(directory.passwordPolicy.resetEmailStatus);
var verificationEmailStatusEnabled = isEnabled(directory.accountCreationPolicy.verificationEmailStatus);

// Enrich config with account policies.
extend(config, {
web: {
forgotPassword: {
enabled: resetEmailStatusEnabled
enabled: config.web.forgotPassword.enabled === false ? false : resetEmailStatusEnabled
},
changePassword: {
enabled: resetEmailStatusEnabled
enabled: config.web.changePassword.enabled === false ? false : resetEmailStatusEnabled
},
verifyEmail: {
enabled: isEnabled(directory.accountCreationPolicy.verificationEmailStatus)
enabled: config.web.verifyEmail.enabled === false ? false : verificationEmailStatusEnabled
}
}
});
Expand Down
80 changes: 68 additions & 12 deletions test/strategy/EnrichIntegrationFromRemoteConfigStrategyTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ describe('EnrichIntegrationFromRemoteConfigStrategy', function () {
});
});

describe('_enrichWithDirectoryPolicies method', function () {
describe('when parsing the directory workflow statuses', function () {
var enrichWithDirectoryPolicies;
var mockConfig;

Expand All @@ -227,27 +227,53 @@ describe('EnrichIntegrationFromRemoteConfigStrategy', function () {
sandbox.stub(policy, 'getStrength').yields(null, {});
});

describe('directory.passwordPolicy.resetEmailStatus property', function () {
describe('the password policy', function () {
describe('when "ENABLED"', function () {
beforeEach(function () {
mockDirectory.passwordPolicy.resetEmailStatus = 'ENABLED';
});

it('should set config.web.forgotPassword.enabled to true', function (done) {
mockConfig.web.forgotPassword.enabled = false;
describe('and config.web.forgotPassword.enabled is false', function () {
it('should leave config.web.forgotPassword.enabled as false', function (done) {
mockConfig.web.forgotPassword.enabled = false;

enrichWithDirectoryPolicies(client, mockConfig, mockDirectory.href, function () {
assert.equal(mockConfig.web.forgotPassword.enabled, true);
done();
enrichWithDirectoryPolicies(client, mockConfig, mockDirectory.href, function () {
assert.equal(mockConfig.web.forgotPassword.enabled, false);
done();
});
});
});

it('should set config.web.changePassword.enabled to true', function (done) {
mockConfig.web.changePassword.enabled = false;
describe('and config.web.forgotPassword.enabled is undefined', function () {
it('should set config.web.forgotPassword.enabled to true', function (done) {
mockConfig.web.forgotPassword.enabled = undefined;

enrichWithDirectoryPolicies(client, mockConfig, mockDirectory.href, function () {
assert.equal(mockConfig.web.changePassword.enabled, true);
done();
enrichWithDirectoryPolicies(client, mockConfig, mockDirectory.href, function () {
assert.equal(mockConfig.web.forgotPassword.enabled, true);
done();
});
});
});

describe('and config.web.changePassword.enabled is false', function () {
it('should leave config.web.changePassword.enabled as false', function (done) {
mockConfig.web.changePassword.enabled = false;

enrichWithDirectoryPolicies(client, mockConfig, mockDirectory.href, function () {
assert.equal(mockConfig.web.changePassword.enabled, false);
done();
});
});
});

describe('and config.web.changePassword.enabled is undefined', function () {
it('should set config.web.changePassword.enabled to true', function (done) {
mockConfig.web.changePassword.enabled = undefined;

enrichWithDirectoryPolicies(client, mockConfig, mockDirectory.href, function () {
assert.equal(mockConfig.web.changePassword.enabled, true);
done();
});
});
});
});
Expand Down Expand Up @@ -276,5 +302,35 @@ describe('EnrichIntegrationFromRemoteConfigStrategy', function () {
});
});
});

describe('the email verification policy', function(){
describe('when ENABLED', function(){
beforeEach(function () {
mockDirectory.accountCreationPolicy.verificationEmailStatus = 'ENABLED';
});

describe('and config.web.verifyEmail.enabled is false', function () {
it('should leave config.web.verifyEmail.enabled as false', function (done) {
mockConfig.web.verifyEmail.enabled = false;

enrichWithDirectoryPolicies(client, mockConfig, mockDirectory.href, function () {
assert.equal(mockConfig.web.verifyEmail.enabled, false);
done();
});
});
});

describe('and config.web.verifyEmail.enabled is undefined', function () {
it('should set config.web.verifyEmail.enabled to true', function (done) {
mockConfig.web.verifyEmail.enabled = undefined;

enrichWithDirectoryPolicies(client, mockConfig, mockDirectory.href, function () {
assert.equal(mockConfig.web.verifyEmail.enabled, true);
done();
});
});
});
});
});
});
});

0 comments on commit 3db8b28

Please sign in to comment.