forked from gavincornwell/cmiserverless
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored repository service to use lambda proxy mode from API gatew…
…ay and added to SAM template. Fixed ‘queryable’ flag on type definitions.
- Loading branch information
Gavin Cornwell
committed
Jan 18, 2017
1 parent
de5d2d8
commit 11ab341
Showing
6 changed files
with
244 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
'use strict'; | ||
|
||
var AWS = require("aws-sdk"); | ||
AWS.config.update({ | ||
region: "eu-central-1" | ||
}); | ||
|
||
let cmisRepositoryService = require('./cmis-repository-service.js'); | ||
|
||
let context = {}; | ||
let typeDefinitionEvent = { | ||
"resource": "/{repoId}", | ||
"path": "/default", | ||
"httpMethod": "GET", | ||
"headers": null, | ||
"queryStringParameters": { | ||
"cmisselector": "typeDefinition", | ||
"typeId": "cmis:folder" | ||
}, | ||
"pathParameters": { | ||
"repoId": "default" | ||
}, | ||
"stageVariables": null, | ||
"requestContext": { | ||
"accountId": "0123456789", | ||
"resourceId": "abcd9876", | ||
"stage": "test-invoke-stage", | ||
"requestId": "test-invoke-request", | ||
"identity": { | ||
"cognitoIdentityPoolId": null, | ||
"accountId": "0123456789", | ||
"cognitoIdentityId": null, | ||
"caller": "ABCDEFGHIJ", | ||
"apiKey": "test-invoke-api-key", | ||
"sourceIp": "test-invoke-source-ip", | ||
"accessKey": "ABCDEFGHIJ", | ||
"cognitoAuthenticationType": null, | ||
"cognitoAuthenticationProvider": null, | ||
"userArn": "arn:aws:iam::0123456789:user/adminuser", | ||
"userAgent": "Apache-HttpClient/4.5.x (Java/1.8.0_102)", | ||
"user": "ABCDEFGHIJ" | ||
}, | ||
"resourcePath": "/{repoId}", | ||
"httpMethod": "GET", | ||
"apiId": "xyz1234" | ||
}, | ||
"body": null, | ||
"isBase64Encoded": false | ||
}; | ||
|
||
let typeDescendantsEvent = { | ||
"resource": "/{repoId}", | ||
"path": "/default", | ||
"httpMethod": "GET", | ||
"headers": null, | ||
"queryStringParameters": { | ||
"cmisselector": "typeDescendants", | ||
"typeId": "cmis:folder" | ||
}, | ||
"pathParameters": { | ||
"repoId": "default" | ||
}, | ||
"stageVariables": null, | ||
"requestContext": { | ||
"accountId": "0123456789", | ||
"resourceId": "abcd9876", | ||
"stage": "test-invoke-stage", | ||
"requestId": "test-invoke-request", | ||
"identity": { | ||
"cognitoIdentityPoolId": null, | ||
"accountId": "0123456789", | ||
"cognitoIdentityId": null, | ||
"caller": "ABCDEFGHIJ", | ||
"apiKey": "test-invoke-api-key", | ||
"sourceIp": "test-invoke-source-ip", | ||
"accessKey": "ABCDEFGHIJ", | ||
"cognitoAuthenticationType": null, | ||
"cognitoAuthenticationProvider": null, | ||
"userArn": "arn:aws:iam::0123456789:user/adminuser", | ||
"userAgent": "Apache-HttpClient/4.5.x (Java/1.8.0_102)", | ||
"user": "ABCDEFGHIJ" | ||
}, | ||
"resourcePath": "/{repoId}", | ||
"httpMethod": "GET", | ||
"apiId": "xyz1234" | ||
}, | ||
"body": null, | ||
"isBase64Encoded": false | ||
}; | ||
|
||
let invalidSelectorEvent = { | ||
"resource": "/{repoId}", | ||
"path": "/default", | ||
"httpMethod": "GET", | ||
"headers": null, | ||
"queryStringParameters": { | ||
"cmisselector": "invalid", | ||
"typeId": "cmis:folder" | ||
}, | ||
"pathParameters": { | ||
"repoId": "default" | ||
}, | ||
"stageVariables": null, | ||
"requestContext": { | ||
"accountId": "0123456789", | ||
"resourceId": "abcd9876", | ||
"stage": "test-invoke-stage", | ||
"requestId": "test-invoke-request", | ||
"identity": { | ||
"cognitoIdentityPoolId": null, | ||
"accountId": "0123456789", | ||
"cognitoIdentityId": null, | ||
"caller": "ABCDEFGHIJ", | ||
"apiKey": "test-invoke-api-key", | ||
"sourceIp": "test-invoke-source-ip", | ||
"accessKey": "ABCDEFGHIJ", | ||
"cognitoAuthenticationType": null, | ||
"cognitoAuthenticationProvider": null, | ||
"userArn": "arn:aws:iam::0123456789:user/adminuser", | ||
"userAgent": "Apache-HttpClient/4.5.x (Java/1.8.0_102)", | ||
"user": "ABCDEFGHIJ" | ||
}, | ||
"resourcePath": "/{repoId}", | ||
"httpMethod": "GET", | ||
"apiId": "xyz1234" | ||
}, | ||
"body": null, | ||
"isBase64Encoded": false | ||
}; | ||
|
||
// run the tests | ||
console.log("Running repository tests..."); | ||
|
||
// retrieve type definition | ||
cmisRepositoryService.handler(typeDefinitionEvent, context, function(error, result) { | ||
if (error) { | ||
console.error("Failed to retrieve type definition: " + JSON.stringify(error, null, 2)); | ||
} else { | ||
|
||
// ensure the status code is present and set to 200 | ||
if (result.statusCode != "200") throw "TEST FAILED: expecting to receive 200 status code"; | ||
|
||
var resultBody = JSON.parse(result.body); | ||
|
||
// ensure there's a typeId property set to "cmis:folder" | ||
if (!resultBody.typeId == "cmis:folder") throw "TEST FAILED: expecting to receive typeId of cmis:folder"; | ||
|
||
// ensure there's a property definition named cmis:objectId | ||
if (!resultBody.propertyDefinitions["cmis:objectId"]) throw "TEST FAILED: expecting to receive cmis:objectId property definition"; | ||
|
||
// if we get this far the tests passed | ||
console.log("Type definition tests passed!"); | ||
} | ||
}); | ||
|
||
// retrieve type descendants | ||
cmisRepositoryService.handler(typeDescendantsEvent, context, function(error, result) { | ||
if (error) { | ||
console.error("Failed to retrieve type descendants: " + JSON.stringify(error, null, 2)); | ||
} else { | ||
|
||
// ensure the status code is present and set to 200 | ||
if (result.statusCode != "200") throw "TEST FAILED: expecting to receive 200 status code"; | ||
|
||
var resultBody = JSON.parse(result.body); | ||
|
||
// ensure an empty array is returned | ||
if (!resultBody.length == 0) throw "TEST FAILED: expecting to receive an empty array"; | ||
|
||
// if we get this far the tests passed | ||
console.log("Type descendants tests passed!"); | ||
} | ||
}); | ||
|
||
// test invalid selector | ||
cmisRepositoryService.handler(invalidSelectorEvent, context, function(error, result) { | ||
if (error) { | ||
console.error(error); | ||
console.log("Invalid selector tests passed!"); | ||
} else { | ||
throw "TEST FAILED: expecting to receive an error"; | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.