Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support allow-unauthorized in aem up #2352

Merged
merged 7 commits into from
May 3, 2024
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',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this is not a very good description... I think allowInsecure would be better

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
Loading