Skip to content

Commit

Permalink
fix: support allow-unauthorized in aem up
Browse files Browse the repository at this point in the history
  • Loading branch information
dominique-pfister committed May 2, 2024
1 parent ef79a85 commit 8d5fef9
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/abstract-server.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class AbstractServerCommand extends AbstractCommand {
this.emit('stopped', this);
}

async initSeverOptions() {
async initServerOptions() {
if (this._cache) {
await fse.ensureDir(this._cache);
this._project.withCacheDirectory(this._cache);
Expand Down
2 changes: 1 addition & 1 deletion src/import.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default class ImportCommand extends AbstractServerCommand {
this.log.info(chalk`{yellow /_/ v${pkgJson.version}}`);
this.log.info('');

await this.initSeverOptions();
await this.initServerOptions();

if (!this._skipUI) {
await this.setupImporterUI();
Expand Down
9 changes: 7 additions & 2 deletions src/up.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ export default class UpCommand extends AbstractServerCommand {
return this;
}

withAllowUnauthorized(value) {
this._allowUnauthorized = value;
return this;
}

async doStop() {
await super.doStop();
if (this._watcher) {
Expand Down Expand Up @@ -79,7 +84,7 @@ export default class UpCommand extends AbstractServerCommand {
await this.verifyUrl(this._gitUrl, ref);
}
this._project.withProxyUrl(this._url);
await this.initSeverOptions();
await this.initServerOptions();

try {
await this._project.init();
Expand Down Expand Up @@ -111,7 +116,7 @@ export default class UpCommand extends AbstractServerCommand {
// "testProperty": "header";
// }
const configUrl = `https://admin.hlx.page/sidekick/${gitUrl.owner}/${gitUrl.repo}/main/config.json`;
const configResp = await getFetch()(configUrl);
const configResp = await getFetch(this._allowUnauthorized)(configUrl);
let previewHostBase = 'hlx.page';
if (configResp.ok) {
// this is best effort for now
Expand Down
7 changes: 7 additions & 0 deletions src/up.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ export default function up() {
type: 'string',
})
.group(['url', 'livereload', 'no-livereload', 'open', 'no-open', 'print-index', 'cache'], 'AEM Options')
.option('allow-unauthorized', {
alias: 'allowUnauthorized',
describe: 'Whether to allow unauthorized access to server',
type: 'boolean',
default: false,
})

.help();
},
Expand All @@ -112,6 +118,7 @@ export default function up() {
.withLiveReload(argv.livereload)
.withUrl(argv.url)
.withPrintIndex(argv.printIndex)
.withAllowUnauthorized(argv.allowUnauthorized)
.withKill(argv.stopOther)
.withCache(argv.alphaCache)
.run();
Expand Down
7 changes: 7 additions & 0 deletions test/up-cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe('hlx up', () => {
mockUp.withBindAddr.returnsThis();
mockUp.withUrl.returnsThis();
mockUp.withPrintIndex.returnsThis();
mockUp.withAllowUnauthorized.returnsThis();
mockUp.withKill.returnsThis();
mockUp.withCache.returnsThis();
mockUp.run.returnsThis();
Expand Down Expand Up @@ -121,6 +122,12 @@ describe('hlx up', () => {
sinon.assert.calledOnce(mockUp.run);
});

it('hlx up can enable allow unauthorized', async () => {
await cli.run(['up', '--allow-unauthorized']);
sinon.assert.calledWith(mockUp.withAllowUnauthorized, true);
sinon.assert.calledOnce(mockUp.run);
});

it('hlx up can enable cache', async () => {
await cli.run(['up', '--alpha-cache', '.cache/']);
sinon.assert.calledWith(mockUp.withCache, '.cache/');
Expand Down

0 comments on commit 8d5fef9

Please sign in to comment.