Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
* Copyright 2018 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
/* eslint-env mocha */
const assert = require('assert');
const { Logger } = require('@adobe/helix-shared');
const check = require('../src/xml/check-xml');
const logger = Logger.getTestLogger({
// tune this for debugging
level: 'info',
});
const context = {
response: {
headers: {
'Content-Type': 'text/plain',
},
body: '',
},
};
describe('Test check-xml', () => {
it('validates proper XML', () => {
check(context, { logger });
it('initFastly generates new backends for defined Proxies', async function test() {
this.polly.server.any().on('beforeResponse', (req) => {
req.removeHeaders(['fastly-key', 'user-agent']);
});
this.polly.configure({
matchRequestsBy: {
body: false,
headers: {
exclude: ['content-length', 'fastly-key', 'user-agent'],
},
},
});
const strainfile = path.resolve(__dirname, 'fixtures/proxystrains.yaml');
const cmd = new PublishCommand(Logger.getTestLogger()).withConfigFile(strainfile);
try {
await cmd.init();
await cmd.initFastly();
} catch (e) {
// we expect initFastly to fail
assert.equal(e.statusCode, 401);
}
assert.equal(Object.keys(cmd._backends).length, 3);
assert.ok(cmd._backends.Proxy1921681001f402);
});
});
it('initFastly generates new backends for defined Proxies', async () => {
const strainfile = path.resolve(__dirname, 'fixtures/proxystrains.yaml');
const cmd = new PublishCommand(Logger.getTestLogger()).withConfigFile(strainfile);
try {
await cmd.init();
await cmd.initFastly();
} catch (e) {
// we expect initFastly to fail
assert.equal(e.statusCode, 401);
}
/* eslint-disable-next-line no-underscore-dangle */
assert.equal(reset(cmd._backends), fs.readFileSync(path.resolve(__dirname, 'fixtures/reset-proxystrains.vcl')).toString());
});
});
.withLogglyHost('loggly-host')
.withDefault({
FOO: 'bar',
})
.withResolveGitRefService('my-resolver')
.run();
assert.equal(cmd.config.strains.get('default').package, '');
assert.equal(cmd.config.strains.get('dev').package, `hlx/${ref}`);
const log = await logger.getOutput();
assert.ok(log.indexOf('deployment of 1 action completed') >= 0);
assert.ok(log.indexOf(`- hlx/${ref}/html`) >= 0);
// check if written helix config contains package ref
const newCfg = new HelixConfig()
.withConfigPath(path.resolve(testRoot, 'helix-config.yaml'));
await newCfg.init();
assert.equal(newCfg.strains.get('default').package, '');
assert.equal(newCfg.strains.get('dev').package, `hlx/${ref}`);
});
// set up a fake git repo.
testRoot = await createTestRoot();
await fs.copy(path.resolve(__dirname, 'fixtures/filtered-master.yaml'), path.resolve(testRoot, 'helix-config.yaml'));
// throw a Javascript error when any shell.js command encounters an error
shell.config.fatal = true;
// init git repo
pwd = shell.pwd();
shell.cd(testRoot);
shell.exec('git init');
shell.exec('git add -A');
shell.exec('git commit -m"initial commit."');
// set up command
const logger = Logger.getTestLogger();
remote = await new ProxiedRemotePublishCommand(logger)
.withWskAuth('fakeauth')
.withWskNamespace('fakename')
.withFastlyAuth('fake_auth')
.withFastlyNamespace('fake_name')
.withWskHost('doesn.t.matter')
.withPublishAPI('https://adobeioruntime.net/api/v1/web/helix/helix-services/publish@v2')
.withConfigFile(path.resolve(__dirname, 'fixtures/filtered.yaml'))
.withDryRun(false);
});
// set up a fake git repo.
testRoot = await createTestRoot();
await fs.copy(path.resolve(__dirname, 'fixtures/filtered-master.yaml'), path.resolve(testRoot, 'helix-config.yaml'));
// throw a Javascript error when any shell.js command encounters an error
shell.config.fatal = true;
// init git repo
pwd = shell.pwd();
shell.cd(testRoot);
shell.exec('git init');
shell.exec('git add -A');
shell.exec('git commit -m"initial commit."');
// set up command
const logger = Logger.getTestLogger();
remote = await new ProxiedRemotePublishCommand(logger)
.withWskAuth('fakeauth')
.withWskNamespace('fakename')
.withFastlyAuth('fake_auth')
.withFastlyNamespace('fake_name')
.withWskHost('doesn.t.matter')
.withPublishAPI('https://adobeioruntime.net/api/v1/web/helix/helix-services/publish@v2')
.withConfigFile(path.resolve(__dirname, 'fixtures/filtered.yaml'))
.withDryRun(false);
});
* Copyright 2018 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
/* eslint-env mocha */
const assert = require('assert');
const { Logger } = require('@adobe/helix-shared');
const link = require('../src/utils/link-handler');
const logger = Logger.getTestLogger({
// tune this for debugging
level: 'info',
});
const action = { logger, secrets: { } };
describe('Test Link Handler', () => {
// test link rewriting
[
{
title: 'Rewrites .md extension to .html',
originalUrl: '/test.md',
expectedUrl: '/test.html',
},
{
title: 'Does not alter URL with non .md extension',
const assertMd = async (md, html, secrets = {}) => {
const fromHTML = (context) => {
context.response = {
status: 201,
body: context.content.document.body.innerHTML,
};
};
const generated = await pipe(
fromHTML,
{ content: { body: multiline(md) }, request: crequest },
{
logger,
request: { params },
secrets,
},
);
// check equality of the dom, but throw assertion based on strings to visualize difference.
const act = new JSDOM(generated.response.body);
const exp = new JSDOM(html);
assertEquivalentNode(act.window.document.body, exp.window.document.body);
};
const assertTransformerYieldsDocument = (transformer, expected) => {
// check equality of the dom, but throw assertion based on strings to visualize difference.
const act = transformer.getDocument();
const dom = new JSDOM(expected);
assertEquivalentNode(act, dom.window.document);
};
};
const generated = await pipe(
fromHTML,
{ content: { body: multiline(md) }, request: crequest },
{
logger,
request: { params },
secrets,
},
);
// check equality of the dom, but throw assertion based on strings to visualize difference.
const act = new JSDOM(generated.response.body);
const exp = new JSDOM(html);
assertEquivalentNode(act.window.document.body, exp.window.document.body);
};