Skip to content

Commit

Permalink
Merge pull request #532 from tpires/fix-531-branding-settings-feature
Browse files Browse the repository at this point in the history
Fixes #531: Unable to deploy without branding settings feature
  • Loading branch information
sergiught authored May 11, 2022
2 parents c47c721 + 88fe0fa commit 1510a85
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 26 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ jobs:
- run:
name: Publish package
command: npm publish

ts_migration_progress:
machine:
image: ubuntu-2004:202111-02
steps:
- checkout
- run :
- run :
name: Typescript Migration Progress
command: sh typescript-migration-progress.sh

Expand All @@ -66,7 +66,7 @@ workflows:
v: "lts"
- test:
name: test_current
v: "current"
v: "18.0.0"
test_and_deploy:
jobs:
- test:
Expand Down
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [7.12.1] - 2022-05-11

### Fixed

- Unable to deploy without branding settings feature [#532]

## [7.12.0] - 2022-05-10

### Added
Expand Down Expand Up @@ -732,7 +738,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#526]: https://github.com/auth0/auth0-deploy-cli/issues/526
[#527]: https://github.com/auth0/auth0-deploy-cli/issues/527
[#530]: https://github.com/auth0/auth0-deploy-cli/issues/530
[unreleased]: https://github.com/auth0/auth0-deploy-cli/compare/v7.12.0...HEAD
[#532]: https://github.com/auth0/auth0-deploy-cli/issues/532
[unreleased]: https://github.com/auth0/auth0-deploy-cli/compare/v7.12.1...HEAD
[7.12.1]: https://github.com/auth0/auth0-deploy-cli/compare/v7.12.0...v7.12.1
[7.12.0]: https://github.com/auth0/auth0-deploy-cli/compare/v7.11.1...v7.12.0
[7.11.1]: https://github.com/auth0/auth0-deploy-cli/compare/v7.11.0...v7.11.1
[7.11.0]: https://github.com/auth0/auth0-deploy-cli/compare/v7.10.0...v7.11.0
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "auth0-deploy-cli",
"version": "7.12.0",
"version": "7.12.1",
"description": "A command line tool for deploying updates to your Auth0 tenant",
"main": "lib/index.js",
"bin": {
Expand Down
15 changes: 11 additions & 4 deletions src/context/directory/handlers/branding.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from 'fs-extra';
import path from 'path';
import { constants, loadFileAndReplaceKeywords } from '../../../tools';
import { dumpJSON, existsMustBeDir, getFiles, loadJSON } from '../../../utils';
import { dumpJSON, existsMustBeDir, getFiles, isFile, loadJSON } from '../../../utils';
import { DirectoryHandler } from '.';
import DirectoryContext from '..';
import { Asset, ParsedAsset } from '../../../types';
Expand All @@ -10,17 +10,24 @@ type ParsedBranding = ParsedAsset<'branding', Asset>;

function parse(context: DirectoryContext): ParsedBranding {
const brandingDirectory = path.join(context.filePath, constants.BRANDING_DIRECTORY);
const brandingFile = path.join(brandingDirectory, 'branding.json');

if (!existsMustBeDir(brandingDirectory)) return { branding: null };

const branding = loadJSON(path.join(brandingDirectory, 'branding.json'), context.mappings);
const brandingSettings = (() => {
if (isFile(brandingFile)) {
return loadJSON(brandingFile, context.mappings);
}

return null;
})();

const brandingTemplatesFolder = path.join(
brandingDirectory,
constants.BRANDING_TEMPLATES_DIRECTORY
);

if (!existsMustBeDir(brandingTemplatesFolder)) return { branding: null };
if (!existsMustBeDir(brandingTemplatesFolder)) return { branding: brandingSettings };

const templatesDefinitionFiles = getFiles(brandingTemplatesFolder, ['.json']);
const templates = templatesDefinitionFiles.map((templateDefinitionFile) => {
Expand All @@ -34,7 +41,7 @@ function parse(context: DirectoryContext): ParsedBranding {

return {
branding: {
...branding,
...brandingSettings,
templates,
},
};
Expand Down
33 changes: 18 additions & 15 deletions test/context/directory/attackProtection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ describe('#directory context attack-protection', () => {
it('should replace keywords', async () => {
const files = {
'attack-protection': {
'breached-password-detection.json': '{"enabled": "@@BREACH_PASSWORD_ENABLED@@", "shields": [], "admin_notification_frequency": [], "method": "##BREACH_PASSWORD_PROT_METHOD##"}',
'brute-force-protection.json': '{"enabled": "@@BRUTE_FORCE_PROT_ENABLED@@", "shields": ["block", "user_notification"], "mode": "count_per_identifier_and_ip", "allowlist": [], "max_attempts": 10}',
'suspicious-ip-throttling.json': '{"enabled": true, "shields": ["block", "admin_notification"], "allowlist": ["127.0.0.1"], "stage": {"pre-login": {"max_attempts": 100, "rate": 864000}, "pre-user-registration": {"max_attempts": 50, "rate": 1200}}}'
}
'breached-password-detection.json':
'{"enabled": "@@BREACH_PASSWORD_ENABLED@@", "shields": [], "admin_notification_frequency": [], "method": "##BREACH_PASSWORD_PROT_METHOD##"}',
'brute-force-protection.json':
'{"enabled": "@@BRUTE_FORCE_PROT_ENABLED@@", "shields": ["block", "user_notification"], "mode": "count_per_identifier_and_ip", "allowlist": [], "max_attempts": 10}',
'suspicious-ip-throttling.json':
'{"enabled": true, "shields": ["block", "admin_notification"], "allowlist": ["127.0.0.1"], "stage": {"pre-login": {"max_attempts": 100, "rate": 864000}, "pre-user-registration": {"max_attempts": 50, "rate": 1200}}}',
},
};

const repoDir = path.join(testDataDir, 'directory', 'attackProtection1');
Expand All @@ -23,8 +26,8 @@ describe('#directory context attack-protection', () => {
AUTH0_KEYWORD_REPLACE_MAPPINGS: {
BREACH_PASSWORD_ENABLED: true,
BREACH_PASSWORD_PROT_METHOD: 'standard',
BRUTE_FORCE_PROT_ENABLED: false
}
BRUTE_FORCE_PROT_ENABLED: false,
},
};

const context = new Context(config, mockMgmtClient());
Expand All @@ -35,30 +38,30 @@ describe('#directory context attack-protection', () => {
admin_notification_frequency: [],
enabled: true,
method: 'standard',
shields: []
shields: [],
},
bruteForceProtection: {
allowlist: [],
enabled: false,
max_attempts: 10,
mode: 'count_per_identifier_and_ip',
shields: [ 'block', 'user_notification' ]
shields: ['block', 'user_notification'],
},
suspiciousIpThrottling: {
allowlist: [ '127.0.0.1' ],
allowlist: ['127.0.0.1'],
enabled: true,
shields: [ 'block', 'admin_notification' ],
shields: ['block', 'admin_notification'],
stage: {
'pre-login': {
max_attempts: 100,
rate: 864000
rate: 864000,
},
'pre-user-registration': {
max_attempts: 50,
rate: 1200
}
}
}
rate: 1200,
},
},
},
};

expect(context.assets.attackProtection).to.deep.equal(target);
Expand Down
43 changes: 43 additions & 0 deletions test/context/directory/branding.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,49 @@ describe('#directory context branding', () => {
]);
});

it('should process only templates, not branding settings', async () => {
const dir = path.join(testDataDir, 'directory', 'branding-process');
cleanThenMkdir(dir);
const brandingDir = path.join(dir, constants.BRANDING_DIRECTORY);
cleanThenMkdir(brandingDir);
const brandingTemplatesDir = path.join(brandingDir, constants.BRANDING_TEMPLATES_DIRECTORY);
cleanThenMkdir(brandingTemplatesDir);

fs.writeFileSync(path.join(brandingTemplatesDir, 'universal_login.html'), html);
fs.writeFileSync(
path.join(brandingTemplatesDir, 'universal_login.json'),
JSON.stringify({ template: 'universal_login', body: `.${path.sep}universal_login.html` })
);

const config = { AUTH0_INPUT_FILE: dir, AUTH0_KEYWORD_REPLACE_MAPPINGS: { foo: 'bar' } };
const context = new Context(config, mockMgmtClient());
await context.load();

expect(context.assets.branding).to.deep.equal({
templates: [
{
template: 'universal_login',
body: htmlTransformed,
},
],
});
});

it('should process only branding settings, not templates', async () => {
const dir = path.join(testDataDir, 'directory', 'branding-process');
cleanThenMkdir(dir);
const brandingDir = path.join(dir, constants.BRANDING_DIRECTORY);
cleanThenMkdir(brandingDir);

fs.writeFileSync(path.join(brandingDir, 'branding.json'), brandingSettings);

const config = { AUTH0_INPUT_FILE: dir, AUTH0_KEYWORD_REPLACE_MAPPINGS: { foo: 'bar' } };
const context = new Context(config, mockMgmtClient());
await context.load();

expect(context.assets.branding).to.deep.equal(JSON.parse(brandingSettings));
});

it('should dump branding settings, including templates', async () => {
const repoDir = path.join(testDataDir, 'directory', 'branding-dump');
cleanThenMkdir(repoDir);
Expand Down

0 comments on commit 1510a85

Please sign in to comment.