- setup
This commit is contained in:
parent
79fe7f4b8b
commit
454b37a0df
1
labs/api/meetings/.gitignore
vendored
Normal file
1
labs/api/meetings/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
node_modules
|
65
labs/api/meetings/Cakefile
Executable file
65
labs/api/meetings/Cakefile
Executable file
@ -0,0 +1,65 @@
|
||||
fs = require 'fs'
|
||||
{print} = require 'util'
|
||||
{spawn, exec} = require 'child_process'
|
||||
glob = require 'glob'
|
||||
|
||||
REPORTER = "min"
|
||||
|
||||
config = {}
|
||||
config.binPath = './node_modules/.bin/'
|
||||
|
||||
# cake test # run all tests
|
||||
# cake -f test/lib/file.coffee test # run the files passed
|
||||
# cake -b test # run all tests and stop at first failure
|
||||
option '-f', '--file [FILE*]', 'input file(s)'
|
||||
option '-b', '--bail', 'bail'
|
||||
task 'test', 'Run the test suite', (options) ->
|
||||
process.env.NODE_ENV = "test"
|
||||
testFiles = [
|
||||
|
||||
]
|
||||
testOpts = [
|
||||
'--require', 'coffee-script/register',
|
||||
'--compilers', 'coffee:coffee-script/register',
|
||||
'--require', 'should',
|
||||
'--colors',
|
||||
'--ignore-leaks',
|
||||
'--timeout', '15000',
|
||||
'--reporter', 'spec'
|
||||
]
|
||||
if options.bail? and options.bail
|
||||
testOpts = testOpts.concat('-b')
|
||||
|
||||
if options.file?
|
||||
if _.isArray(options.file)
|
||||
files = testFiles.concat(options.file)
|
||||
else
|
||||
files = testFiles.concat([options.file])
|
||||
for opt in testOpts.reverse()
|
||||
files.unshift opt
|
||||
run 'mocha', files
|
||||
|
||||
else
|
||||
glob 'test/**/*.coffee', (error, files) ->
|
||||
for opt in testOpts.reverse()
|
||||
files.unshift opt
|
||||
run 'mocha', files
|
||||
|
||||
# Internal methods
|
||||
|
||||
# Spawns an application with `options` and calls `onExit`
|
||||
# when it finishes.
|
||||
run = (bin, options, onExit) ->
|
||||
bin = config.binPath + bin
|
||||
console.log timeNow() + ' - running: ' + bin + ' ' + (if options? then options.join(' ') else "")
|
||||
cmd = spawn bin, options
|
||||
cmd.stdout.on 'data', (data) -> print data.toString()
|
||||
cmd.stderr.on 'data', (data) -> print data.toString()
|
||||
cmd.on 'exit', (code) ->
|
||||
console.log 'done.'
|
||||
onExit?(code, options)
|
||||
|
||||
# Returns a string with the current time to print out.
|
||||
timeNow = ->
|
||||
today = new Date()
|
||||
today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds()
|
41
labs/api/meetings/README.md
Normal file
41
labs/api/meetings/README.md
Normal file
@ -0,0 +1,41 @@
|
||||
exploringHapi
|
||||
=============
|
||||
|
||||
This was used as a playground for attempts to validate URL parameters
|
||||
and to calculate and compare checksum
|
||||
|
||||
Keywords: hapi, joi, OAuth, checksum, hmac_sha1
|
||||
|
||||
Instructions:
|
||||
=============
|
||||
from Terminal:
|
||||
$ coffee index.coffee
|
||||
Listening on http://x.x.x.x:PORT
|
||||
|
||||
go to the browser, open an MCONF API-MATE window
|
||||
modify the "server"(id="input-custom-server-url") field to http://x.x.x.x:PORT
|
||||
click on the link for creating a meeting ("create ...")
|
||||
|
||||
In the Terminal window you should see something like:
|
||||
the checksum from url is
|
||||
e8b540ab61a71c46ebc99e7250e2ca6372115d9a and mine is
|
||||
e8b540ab61a71c46ebc99e7250e2ca6372115d9a
|
||||
YAY! They match!
|
||||
|
||||
or
|
||||
|
||||
the checksum from url is
|
||||
e8b540ab61a71c46ebc99e7250e2ca6372115d9a and mine is
|
||||
dkfjhdkjfhlkafhdfklahfkfhfjhkgfeq349492a
|
||||
|
||||
The browser window will display
|
||||
"everything is fine" if the parameter validation was successful
|
||||
or Error if it was not
|
||||
|
||||
|
||||
LOGGING
|
||||
# To use for CLI
|
||||
npm install -g bunyan
|
||||
|
||||
https://github.com/trentm/node-bunyan
|
||||
|
17
labs/api/meetings/index.coffee
Executable file
17
labs/api/meetings/index.coffee
Executable file
@ -0,0 +1,17 @@
|
||||
Hapi = require("hapi")
|
||||
pack = require './package'
|
||||
routes = require './lib/routes'
|
||||
bunyan = require 'bunyan'
|
||||
|
||||
log = bunyan.createLogger({name: 'myapp'});
|
||||
log.info('hi')
|
||||
log.warn({lang: 'fr'}, 'au revoir')
|
||||
|
||||
server = Hapi.createServer("0.0.0.0", parseInt(process.env.PORT, 10) or 4000)
|
||||
|
||||
server.start(() ->
|
||||
log.info(['start'], pack.name + ' - web interface: ' + server.info.uri);
|
||||
)
|
||||
|
||||
server.route routes.routes
|
||||
|
30
labs/api/meetings/lib/handlers.coffee
Executable file
30
labs/api/meetings/lib/handlers.coffee
Executable file
@ -0,0 +1,30 @@
|
||||
hapi = require 'hapi'
|
||||
Joi = require 'joi'
|
||||
util = require './util'
|
||||
sha1 = require 'js-sha1'
|
||||
|
||||
sharedSecret = '8cd8ef52e8e101574e400365b55e11a6'
|
||||
|
||||
index = (req, resp) ->
|
||||
resp "Hello World!"
|
||||
|
||||
createHandler = (req, resp) ->
|
||||
console.log("CREATE: " + req.originalUrl )
|
||||
checksum = req.query.checksum
|
||||
console.log("checksum = [" + checksum + "]")
|
||||
|
||||
query = util.removeChecksumFromQuery(req.query)
|
||||
|
||||
baseString = util.buildCreateBaseString(query)
|
||||
ourChecksum = util.calculateChecksum("create", baseString, sharedSecret)
|
||||
|
||||
console.log "the checksum from url is \n" + checksum + " and mine is\n" + ourChecksum
|
||||
|
||||
if checksum isnt ourChecksum
|
||||
resp "Fail!"
|
||||
else
|
||||
resp "everything is fine"
|
||||
|
||||
|
||||
exports.index = index
|
||||
exports.create = createHandler
|
33
labs/api/meetings/lib/routes.coffee
Executable file
33
labs/api/meetings/lib/routes.coffee
Executable file
@ -0,0 +1,33 @@
|
||||
hapi = require 'hapi'
|
||||
handlers = require './handlers'
|
||||
Joi = require 'joi'
|
||||
|
||||
createValidation =
|
||||
attendeePW: Joi.string().max(20).required()
|
||||
checksum: Joi.string().required()
|
||||
meetingID: Joi.string().min(3).max(30).required()
|
||||
moderatorPW: Joi.string().required()
|
||||
name: Joi.string().regex(/[a-zA-Z0-9]{3,30}/)
|
||||
record: Joi.boolean()
|
||||
voiceBridge: Joi.string()
|
||||
welcome: Joi.string()
|
||||
|
||||
routes = [{
|
||||
method: 'GET',
|
||||
path: '/',
|
||||
config: {
|
||||
handler: handlers.index
|
||||
}
|
||||
}, {
|
||||
method: "GET",
|
||||
path: "/bigbluebutton/api/create",
|
||||
config: {
|
||||
handler: handlers.create,
|
||||
validate: {
|
||||
query: createValidation
|
||||
}
|
||||
}
|
||||
}];
|
||||
|
||||
|
||||
exports.routes = routes;
|
32
labs/api/meetings/lib/util.coffee
Executable file
32
labs/api/meetings/lib/util.coffee
Executable file
@ -0,0 +1,32 @@
|
||||
sha1 = require 'js-sha1'
|
||||
|
||||
|
||||
|
||||
removeChecksumFromQuery = (query) ->
|
||||
for own propName of query
|
||||
console.log(propName + "=" + query[propName])
|
||||
delete query['checksum']
|
||||
query
|
||||
|
||||
buildCreateBaseString = (query) ->
|
||||
baseString = ""
|
||||
for own propName of query
|
||||
propVal = query[propName]
|
||||
if (propName == "welcome")
|
||||
propVal = encodeURIComponent(query.welcome).replace(/%20/g, '+').replace(/[!'()]/g, escape).replace(/\*/g, "%2A")
|
||||
baseString += propName + "=" + propVal + "&"
|
||||
console.log(propName + "=" + query[propName])
|
||||
|
||||
console.log("baseString=[" + baseString.slice(0, -1) + "]")
|
||||
|
||||
baseString.slice(0, -1)
|
||||
|
||||
calculateChecksum = (method, baseString, sharedSecret) ->
|
||||
qStr = method + baseString + sharedSecret
|
||||
console.log("[" + qStr + "]")
|
||||
sha1(qStr)
|
||||
|
||||
|
||||
exports.removeChecksumFromQuery = removeChecksumFromQuery
|
||||
exports.buildCreateBaseString = buildCreateBaseString
|
||||
exports.calculateChecksum = calculateChecksum
|
23
labs/api/meetings/package.json
Executable file
23
labs/api/meetings/package.json
Executable file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "exploringHapi",
|
||||
"version": "0.0.2",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"start": "coffee index.coffee"
|
||||
},
|
||||
"dependencies": {
|
||||
"hapi": "2.6.0",
|
||||
"joi": "2.7.0",
|
||||
"coffee-script": "1.7.1",
|
||||
"js-sha1": "0.1.1",
|
||||
"bunyan": "0.22.2",
|
||||
"glob": "3.2.6"
|
||||
},
|
||||
"devDependencies": {
|
||||
"coffee-script": "1.7.1",
|
||||
"mocha": "1.18.2",
|
||||
"should": "3.3.1",
|
||||
"glob": "3.2.6",
|
||||
"chai": "1.9.x"
|
||||
}
|
||||
}
|
3
labs/api/meetings/test/test_helper.coffee
Executable file
3
labs/api/meetings/test/test_helper.coffee
Executable file
@ -0,0 +1,3 @@
|
||||
|
||||
|
||||
|
11
labs/api/meetings/test/testc.coffee
Executable file
11
labs/api/meetings/test/testc.coffee
Executable file
@ -0,0 +1,11 @@
|
||||
assert = require("assert")
|
||||
|
||||
describe "Array", ->
|
||||
|
||||
describe '#indexOf()', ->
|
||||
|
||||
it 'should return -1 when the value is not present', ->
|
||||
assert.equal(-1, [1,2,3].indexOf(5))
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user