-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds tests for HTTP device sample #534
Changes from 4 commits
821d10a
c143e9a
b8f3a1f
95e6262
bfd5b29
b067b65
d118f5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Test public certificate files | ||
|
||
The public certificates in this folder are only provided for testing and should | ||
not be used for registering your devices. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we use these in our CI tests - if so, I assume they are sufficiently secure? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, these certificates are used in our CI tests. The authorization credentials are revoked when the tests tear down. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIC9TCCAd2gAwIBAgIJALM44e3ivEWkMA0GCSqGSIb3DQEBCwUAMBExDzANBgNV | ||
BAMMBnVudXNlZDAeFw0xNzEyMDcwMDQ1MjdaFw0yNzEyMDUwMDQ1MjdaMBExDzAN | ||
BgNVBAMMBnVudXNlZDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAL4w | ||
BxHuEyYdbiwKiD8yXY7vYpcygeOQ4/ZdEg3wCB2OuYcaFRcCuqLcTLMnuzdcL+y3 | ||
HBjWkrRW658cg3NG93Vj0iwSrga6u24CGBNYV+h8MBvwaDxk+uubnd5M/Q2OyL1J | ||
GiMxQ1blR/71Hr5hhqaQZ2+qOF6kuf1m9rLUtMUJwOKp/PjPDmy654ZGsFWFSZmy | ||
eRpNzmGU+KJg0o+Qf+sm75a8gQZ8AsrqveW0S/8o+zAjD0SkPcd01QBmYzQhjbi/ | ||
LGGITrzbaB3ld9umJBIcXfnYPYisJfwSsT/jFwiXhrhpxNNaIaKlTzlQIt5l8bSs | ||
HXzJBbuIg5Jb/SyIEpkCAwEAAaNQME4wHQYDVR0OBBYEFOfaQTUVAoNb6fc7qzzl | ||
uKyHGrCYMB8GA1UdIwQYMBaAFOfaQTUVAoNb6fc7qzzluKyHGrCYMAwGA1UdEwQF | ||
MAMBAf8wDQYJKoZIhvcNAQELBQADggEBALKKDtiV1YV8k0YsNdiIXRlS3jsuoGuI | ||
VVBrvDGz5Hel0rH9YmmfPS/Yn08kk3DF8Uynr4Xo1Zt9hmhgoq3ZoWm7MIP1+a9s | ||
WyACyEMhVQSCzQrexRvG5ElpHx/vNjbcwiBkE5urlIvMBVt+BRRNKMNWq6F9ae63 | ||
FxRp7CtNFSbibtLJuPgCs6qoNs0nlt2FPsNvs7jpPipj69o+egVckvQjAyppirWO | ||
+jO5hCLy7EahLz2wCn90z0Xf9lhOZni9meaV1Vy3CHHg6jwIB8/XlRaHFrOGMGXg | ||
h8eQqsmpk9/3o8pv00yj6Hkq+swVg7Rg9FZaUiOv/HO/J7stWU7qPbI= | ||
-----END CERTIFICATE----- |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
-----BEGIN PRIVATE KEY----- | ||
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQC+MAcR7hMmHW4s | ||
Cog/Ml2O72KXMoHjkOP2XRIN8AgdjrmHGhUXArqi3EyzJ7s3XC/stxwY1pK0Vuuf | ||
HINzRvd1Y9IsEq4GurtuAhgTWFfofDAb8Gg8ZPrrm53eTP0Njsi9SRojMUNW5Uf+ | ||
9R6+YYamkGdvqjhepLn9Zvay1LTFCcDiqfz4zw5suueGRrBVhUmZsnkaTc5hlPii | ||
YNKPkH/rJu+WvIEGfALK6r3ltEv/KPswIw9EpD3HdNUAZmM0IY24vyxhiE6822gd | ||
5XfbpiQSHF352D2IrCX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FJRwzLslckJM7g628loYfYAew+zrZrG4dsDjNG0Sw3zlAgeUAbQ | ||
D+2iVhZf61josFiRuMP3t9paEi+vAFk4C3KSz/ECgYBpi1akpIzsYehW5uOL7Jhw | ||
Hay5eshQ4vmHYuhDnn3gtT3h6J7TMwWs9pOygBG1I1b7GJ+tp4BZWJ2PmI7P8s45 | ||
jdI99WODHwv03lAzjLwigoqDUDduaYqXcGghcGht5Sknkl2uYDChwLtI5JdBZ9/x | ||
8h9dE9oAiH/KTzhPmK1E1Q== | ||
-----END PRIVATE KEY----- |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/** | ||
* Copyright 2017, Google, Inc. | ||
* Licensed 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 CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const path = require(`path`); | ||
const PubSub = require(`@google-cloud/pubsub`); | ||
const test = require(`ava`); | ||
const tools = require(`@google-cloud/nodejs-repo-tools`); | ||
const uuid = require(`uuid`); | ||
|
||
const deviceId = `test-node-device`; | ||
const topicName = `nodejs-docs-samples-test-iot-${uuid.v4()}`; | ||
const registryName = `nodejs-test-registry-iot-${uuid.v4()}`; | ||
const helper = `node ../manager/manager.js`; | ||
const cmd = `node cloudiot_http_example.js --registry_id="${registryName}" --device_id="${deviceId}" `; | ||
const cwd = path.join(__dirname, `..`); | ||
|
||
test.before(tools.checkCredentials); | ||
test.before(async () => { | ||
const pubsub = PubSub(); | ||
return pubsub.createTopic(topicName) | ||
.then((results) => { | ||
const topic = results[0]; | ||
console.log(`Topic ${topic.name} created.`); | ||
return topic; | ||
}); | ||
}); | ||
|
||
test.after.always(async () => { | ||
const pubsub = PubSub(); | ||
const topic = pubsub.topic(topicName); | ||
return topic.delete() | ||
.then(() => { | ||
console.log(`Topic ${topic.name} deleted.`); | ||
}); | ||
}); | ||
|
||
test(`should receive configuration message`, async (t) => { | ||
const localDevice = `test-rsa-device`; | ||
const localRegName = `${registryName}-rsa256`; | ||
await tools.runAsync(`${helper} setupIotTopic ${topicName}`, cwd); | ||
await tools.runAsync( | ||
`${helper} createRegistry ${localRegName} ${topicName}`, cwd); | ||
await tools.runAsync( | ||
`${helper} createRsa256Device ${localDevice} ${localRegName} resources/rsa_cert.pem`, cwd); | ||
|
||
let output = await tools.runAsync( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: can these be |
||
`${cmd} --message_type=events --num_messages=1 --private_key_file=resources/rsa_private.pem --algorithm=RS256`, cwd); | ||
|
||
t.regex(output, new RegExp(/Getting config/)); | ||
|
||
// Check / cleanup | ||
await tools.runAsync(`${helper} getDeviceState ${localDevice} ${localRegName}`, cwd); | ||
await tools.runAsync(`${helper} deleteDevice ${localDevice} ${localRegName}`, cwd); | ||
await tools.runAsync(`${helper} deleteRegistry ${localRegName}`, cwd); | ||
}); | ||
|
||
test(`should send event message`, async (t) => { | ||
const localDevice = `test-rsa-device`; | ||
const localRegName = `${registryName}-rsa256`; | ||
await tools.runAsync(`${helper} setupIotTopic ${topicName}`, cwd); | ||
await tools.runAsync( | ||
`${helper} createRegistry ${localRegName} ${topicName}`, cwd); | ||
await tools.runAsync( | ||
`${helper} createRsa256Device ${localDevice} ${localRegName} resources/rsa_cert.pem`, cwd); | ||
|
||
let output = await tools.runAsync( | ||
`${cmd} --message_type=events --num_messages=1 --private_key_file=resources/rsa_private.pem --algorithm=RS256`, cwd); | ||
|
||
t.regex(output, new RegExp(/Publishing message/)); | ||
|
||
// Check / cleanup | ||
await tools.runAsync(`${helper} getDeviceState ${localDevice} ${localRegName}`, cwd); | ||
await tools.runAsync(`${helper} deleteDevice ${localDevice} ${localRegName}`, cwd); | ||
await tools.runAsync(`${helper} deleteRegistry ${localRegName}`, cwd); | ||
}); | ||
|
||
test(`should send event message`, async (t) => { | ||
const localDevice = `test-rsa-device`; | ||
const localRegName = `${registryName}-rsa256`; | ||
await tools.runAsync(`${helper} setupIotTopic ${topicName}`, cwd); | ||
await tools.runAsync( | ||
`${helper} createRegistry ${localRegName} ${topicName}`, cwd); | ||
await tools.runAsync( | ||
`${helper} createRsa256Device ${localDevice} ${localRegName} resources/rsa_cert.pem`, cwd); | ||
|
||
let output = await tools.runAsync( | ||
`${cmd} --message_type=state --num_messages=1 --private_key_file=resources/rsa_private.pem --algorithm=RS256`, cwd); | ||
t.regex(output, new RegExp(/Publishing message/)); | ||
|
||
// Check / cleanup | ||
await tools.runAsync(`${helper} getDeviceState ${localDevice} ${localRegName}`, cwd); | ||
await tools.runAsync(`${helper} deleteDevice ${localDevice} ${localRegName}`, cwd); | ||
await tools.runAsync(`${helper} deleteRegistry ${localRegName}`, cwd); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: s/snake_case/camelCase/g