Skip to content
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

Error class gotcha #72

Open
jasonblanchard opened this issue Oct 10, 2017 · 0 comments
Open

Error class gotcha #72

jasonblanchard opened this issue Oct 10, 2017 · 0 comments

Comments

@jasonblanchard
Copy link

It looks like the error classes don't behave like a Javascript Error:

it.only 'should return false if nonce already seen', (done) =>
      req =
        url: '/test'
        method: 'POST'
        connection:
          encrypted: undefined
        headers:
          host: 'localhost'
        body:
          lti_message_type: 'basic-lti-launch-request'
          lti_version: 'LTI-1p0'
          resource_link_id: 'http://link-to-resource.com/resource'
          oauth_customer_key: 'key'
          oauth_signature_method: 'HMAC-SHA1'
          oauth_timestamp: Math.round(Date.now()/1000)
          oauth_nonce: Date.now()+Math.random()*100

      #sign the fake request
      signature = @provider.signer.build_signature(req, req.body, 'secret')
      req.body.oauth_signature = signature

      @provider.valid_request req, (err, valid) =>
        should.not.exist err
        valid.should.equal true
        @provider.valid_request req, (err, valid) ->
          should.exist err
          console.log('Message: ', err.message);
          console.log('Stack: ', err.stack);
          err.should.be.instanceof(lti.Errors.NonceError)
          valid.should.equal false
          done()

which will print out:

Message:  Expired nonce
Stack:  undefined

vs changing this line to:

callback new Error('Expired nonce'), false

which will print out:

Message:  Expired nonce
Stack:  Error: Expired nonce
    at /Users/jason/oss/ims-lti/lib/provider.js:204:27
    at MemoryNonceStore.isNew (/Users/jason/oss/ims-lti/lib/memory-nonce-store.js:82:16)
    at Provider._valid_oauth (/Users/jason/oss/ims-lti/lib/provider.js:200:30)
    at Provider.valid_request (/Users/jason/oss/ims-lti/lib/provider.js:169:19)
    at Provider.valid_request (/Users/jason/oss/ims-lti/lib/provider.js:88:59)
    at /Users/jason/oss/ims-lti/test/Provider.coffee:326:19
    at /Users/jason/oss/ims-lti/lib/provider.js:207:18
    at /Users/jason/oss/ims-lti/lib/memory-nonce-store.js:98:20
    at MemoryNonceStore.setUsed (/Users/jason/oss/ims-lti/lib/memory-nonce-store.js:117:14)
    at MemoryNonceStore.isNew (/Users/jason/oss/ims-lti/lib/memory-nonce-store.js:85:19)

    at Provider._valid_oauth (/Users/jason/oss/ims-lti/lib/provider.js:200:30)
    at Provider.valid_request (/Users/jason/oss/ims-lti/lib/provider.js:169:19)
    at Provider.valid_request (/Users/jason/oss/ims-lti/lib/provider.js:88:59)
    at Context.<anonymous> (/Users/jason/oss/ims-lti/test/Provider.coffee:323:17)
    at callFnAsync (/Users/jason/oss/ims-lti/node_modules/mocha/lib/runnable.js:349:8)
    at Test.Runnable.run (/Users/jason/oss/ims-lti/node_modules/mocha/lib/runnable.js:301:7)
    at Runner.runTest (/Users/jason/oss/ims-lti/node_modules/mocha/lib/runner.js:422:10)
    at /Users/jason/oss/ims-lti/node_modules/mocha/lib/runner.js:528:12
    at next (/Users/jason/oss/ims-lti/node_modules/mocha/lib/runner.js:342:14)
    at /Users/jason/oss/ims-lti/node_modules/mocha/lib/runner.js:352:7
    at next (/Users/jason/oss/ims-lti/node_modules/mocha/lib/runner.js:284:14)
    at Immediate.<anonymous> (/Users/jason/oss/ims-lti/node_modules/mocha/lib/runner.js:320:5)
    at runCallback (timers.js:651:20)
    at tryOnImmediate (timers.js:624:5)
    at processImmediate [as _immediateCallback] (timers.js:596:5)

This can cause issues if calling code is expecting to find a useful stack trace or is using something like nested error stacks. There might be other subtle differences, too, but the lack of a stack trace is the one that puzzled me today.

It seems like the class inheritance isn't working as expected? It could be related to this coffeescript bug, but I know literally nothing about coffeescript, so hard to tell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant