Skip to content

Commit

Permalink
Fix replacing host from environment variable AWS_ENDPOINT_URL (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgenfb authored Jan 5, 2024
1 parent 2a3384d commit 4039810
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
23 changes: 22 additions & 1 deletion spec/unit/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,28 @@ describe("LocalstackPlugin", () => {
expect(request.called).to.be.true;
let templateUrl = request.firstCall.args[2].TemplateURL;
// url should either start with 'http://localhost' or 'http://127.0.0.1
expect(templateUrl).to.satisfy((url) => url.startsWith(`${config.host}`) || url.startsWith('http://127.0.0.1'));
expect(templateUrl).to.satisfy((url) => url === `${config.host}:4566/path/to/template` || url === 'http://127.0.0.1:4566/path/to/template');
});

it('should overwrite the S3 hostname with the value from environment variable', async () => {
// Set environment variable to overwrite the default host
process.env.AWS_ENDPOINT_URL = 'http://localstack:4566';

const pathToTemplate = 'https://s3.amazonaws.com/path/to/template';
const request = sinon.stub(awsProvider, 'request');
instance = new LocalstackPlugin(serverless, defaultPluginState);
await simulateBeforeDeployHooks(instance);

await awsProvider.request('s3', 'foo', {
TemplateURL: pathToTemplate
});

// Remove the environment variable again to not affect other tests
delete process.env.AWS_ENDPOINT_URL

expect(request.called).to.be.true;
let templateUrl = request.firstCall.args[2].TemplateURL;
expect(templateUrl).to.equal('http://localstack:4566/path/to/template');
});

it('should not send validateTemplate calls to localstack', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,7 @@ class LocalstackPlugin {
if (hostname && url.hostname === 'localhost') {
url.hostname = hostname;
}
return url.href;
return url.origin;
}

log(msg) {
Expand Down

0 comments on commit 4039810

Please sign in to comment.