Skip to content
This repository has been archived by the owner on Jul 31, 2020. It is now read-only.

Commit

Permalink
Test: requestUtil constructor expired credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
ayumi committed Dec 29, 2016
1 parent 481c776 commit 887ef39
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 7 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,12 @@ To integrate Brave sync on a platform (iOS, Android, Laptop):
4. If developing, do `npm start` in browser-laptop. Console messages from the
sync client will be logged in `Library/Application
Support/brave-development/chrome-debug.log`.

### Tests

To run tests you need to configure these environment variables:

- AWS_REGION
- AWS_S3_BUCKET
- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY
30 changes: 28 additions & 2 deletions test/client/requestUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ const proto = require('../../client/constants/proto')
test('client RequestUtil', (t) => {
t.plan(1)
t.test('constructor', (t) => {
t.plan(5)
t.plan(6)

Serializer.init().then((serializer) => {
clientTestHelper.getSerializedCredentials(serializer).then((data) => {
const keys = data.keys
const args = [
serializer,
data.serializedCredentials,
clientTestHelper.config.apiVersion,
clientTestHelper.CONFIG.apiVersion,
data.userId
]
t.throws(() => { return new RequestUtil() }, 'requires arguments')
Expand All @@ -29,6 +29,14 @@ test('client RequestUtil', (t) => {
t.test('prototype', (t) => {
testPrototype(t, requestUtil, keys)
})

const expiredCredentials = {
aws: clientTestHelper.EXPIRED_CREDENTIALS.aws,
s3Post: clientTestHelper.EXPIRED_CREDENTIALS.s3Post,
bucket: requestUtil.bucket,
region: requestUtil.region
}
testExpiredCredentials(t, expiredCredentials, keys, serializer)
}).catch((error) => { t.end(error) })
})
})
Expand Down Expand Up @@ -148,4 +156,22 @@ test('client RequestUtil', (t) => {
})
}
}

const testExpiredCredentials = (t, expiredCredentials, keys, serializer) => {
t.test('RequestUtil with expired credentials', (t) => {
t.plan(1)
const userId = Buffer.from(keys.publicKey).toString('base64')
const args = [
serializer,
serializer.credentialsToByteArray(expiredCredentials),
clientTestHelper.CONFIG.apiVersion,
userId
]
let requestUtil
t.doesNotThrow(
() => { requestUtil = new RequestUtil(...args) },
`${t.name} instantiates without error`
)
})
}
})
30 changes: 25 additions & 5 deletions test/client/testHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,30 @@
* apiVersion: <string>
* }}
*/
module.exports.config = {
apiVersion: '0'
const CONFIG = {
apiVersion: '0',
serverUrl: 'http://localhost:4000'
}
module.exports.CONFIG = CONFIG

/**
* For testing recovery from expired credentials.
*/
const EXPIRED_CREDENTIALS = {
aws: {
accessKeyId: "ASIAJWDZEARJIRDPKHCA",
secretAccessKey: "UWE6jt/VTgvyr9s1A8cGgQJKRZgpnSrFfNtbbVGQ",
sessionToken: "FQoDYXdzEPj//////////wEaDMcXJlV2DDdqPcV6tSKjA6DuDSolA5d1kxuuZiCbxPjR439unlaxtIIHLe/NCI9EbhxX2sRYW5ke244fobOYIgnyO9+cm28sqZdewM4LvYYgYwivwc3Ud9zmDzW14ZtJUSVXbj4WU0XHH106bV7RpQ52fTnG55sNfdhWndY1ptHBQzifWa3aKhGGQ4gpDPa+lGb5VaSlgMXqutzn8nVXA801MmwZXbfcT7QjloP8Qio4hnVQQptXfTlXoNsjPdmu7N8ZEUrnwZ4UmHIt4xbZ8GsM2YYBbuCroQjsvsc03eBhJ4HcAcx6G8W3pUDl8D0JbbgEEtwjwSHLJQ2tpUp8GKXPryp7NnU3HGAdgXWYZUY5AncXBySEZwF2PqjSuj3DuMQUuTURtvbbehKypFQ6ogAQb2OX7pzn8o/WnI/m7MS5rsIi9w0QdePzg6zGh4PtcHG4mpSqTbqsga6OQYLFW1d2DnS8hOz2h3cav3nmIF42r1/rLeiuqefUcwuVu6L9MCV7hw99rzUAOqQdKx8eh1bKU+lK1x3aypB2eLRicPyhOy3mUPs4JaDrqNnfwkViclN0KM3d0cIF",
expiration: "2016-12-25T04:20:00Z"
},
s3Post: {
AWSAccessKeyId: 'AKIAIBFRINGWH5WYZLLQ',
policy: 'eyAiZXhwaXJhdGlvbiI6ICIyMDE2LTEyLTI4VDA1OjQ4OjE2LjE2NVoiLCAiY29uZGl0aW9ucyI6IFsgeyJidWNrZXQiOiAiYnJhdmUtc3luYy10ZXN0In0sIFsic3RhcnRzLXdpdGgiLCAiJGtleSIsICIwL2ppcndzWjUxNFE0NUxZUVFZZ3lFNVJJVDBQNWRxWnVTc0ZVcWNMZ1c3Y289Il0sIHsiYWNsIjogInByaXZhdGUifSwgWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsIDAsIDBdIF0gfQ==',
signature: 'y3Ow85qyiEq51hFx9IfG8k7G2ik=',
acl: 'private'
}
}
module.exports.EXPIRED_CREDENTIALS = EXPIRED_CREDENTIALS

/**
* This is the browser JS version, wherein protobuf js records which take
Expand Down Expand Up @@ -53,8 +74,7 @@ module.exports.Encrypt = (serializer, secretboxKey) => {
module.exports.getSerializedCredentials = (serializer) => {
const crypto = require('../../lib/crypto')

const serverUrl = `http://localhost:4000`
console.log(`Connecting to ${serverUrl}`)
console.log(`Connecting to ${CONFIG.serverUrl}`)
const keys = crypto.deriveKeys(crypto.getSeed())
const userId = Buffer.from(keys.publicKey).toString('base64')

Expand All @@ -66,7 +86,7 @@ module.exports.getSerializedCredentials = (serializer) => {
method: 'POST',
body: signedTimestamp
}
return window.fetch(`${serverUrl}/${encodeURIComponent(userId)}/credentials`, params)
return window.fetch(`${CONFIG.serverUrl}/${encodeURIComponent(userId)}/credentials`, params)
.then((response) => {
if (!response.ok) {
throw new Error('Credential server response ' + response.status)
Expand Down

0 comments on commit 887ef39

Please sign in to comment.