Skip to content

Commit

Permalink
bonsai
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW committed Jan 10, 2018
1 parent afcf9fa commit 03f31d4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
7 changes: 7 additions & 0 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ custom:
- bucketName: ${self:provider.environment.WEBSITE_S3_BUCKET_NAME}
localDir: src

package:
exclude:
- src/*
- test/*
- package.json
- README.md

functions:
basicAuth:
name: '${self:provider.environment.WEBSITE_S3_BUCKET_NAME}-viewer-request'
Expand Down
33 changes: 32 additions & 1 deletion test/basicAuth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const path = require('path');

const { basicAuth } = require(path.join(__dirname, '..', 'handler.js'));

test.cb('handler.basicAuth check user/pass', (t) => {
test.cb('handler.basicAuth pass valid user/pass', (t) => {
const event = {
Records: [
{
Expand All @@ -29,3 +29,34 @@ test.cb('handler.basicAuth check user/pass', (t) => {

basicAuth(event, context, callback);
});

test.cb('handler.basicAuth fail invalid user/pass', (t) => {
const event = {
Records: [
{
cf: {
request: {
headers: {
authorization: [{ key: 'Authorization', value: 'Basic invalid' }]
}
}
}
}
]
};
const context = {};
const callback = (error, response) => {
t.deepEqual(response, {
status: '401',
statusDescription: 'Authorization Required',
headers: {
'www-authenticate': [{ key: 'WWW-Authenticate', value: 'Basic' }],
'content-type': [{ key: 'Content-Type', value: 'text/plain; charset=utf-8' }]
},
body: '401 Authorization Required'
});
t.end();
};

basicAuth(event, context, callback);
});

0 comments on commit 03f31d4

Please sign in to comment.