strategy.test.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. var chai = require('chai');
  2. var sinon = require('sinon');
  3. var Strategy = require('../lib/strategy');
  4. describe('Strategy', function() {
  5. it('should be named ethereum', function() {
  6. var strategy = new Strategy(function(){});
  7. expect(strategy.name).to.equal('ethereum');
  8. });
  9. it('should verify address', function(done) {
  10. chai.passport.use(new Strategy(function(address, cb) {
  11. expect(address).to.equal('0xCC6F4DF4B758C4DE3203e8842E2d8CAc564D7758');
  12. return cb(null, { id: '248289761001' });
  13. }))
  14. .request(function(req) {
  15. req.connection = {};
  16. req.headers.host = 'localhost:3000';
  17. req.body = {
  18. message: 'localhost:3000 wants you to sign in with your Ethereum account:\n' +
  19. '0xCC6F4DF4B758C4DE3203e8842E2d8CAc564D7758\n' +
  20. '\n' +
  21. 'Sign in with Ethereum to the app.\n' +
  22. '\n' +
  23. 'URI: http://localhost:3000\n' +
  24. 'Version: 1\n' +
  25. 'Chain ID: 1\n' +
  26. 'Nonce: VjglqeaSMDbPSYe0K\n' +
  27. 'Issued At: 2022-06-07T16:28:10.957Z',
  28. signature: '0xb303d03782c532e2371e3d75a8b2b093c2dceb5faed5d07d6506be96be783245515db6ad55ad6d598ebdf1f7e1c5cb0d24e7147bbad47d3b9d8dfbcfab2ddcc71b'
  29. };
  30. req.session = {
  31. messages: [],
  32. ethereum: {
  33. nonce: 'VjglqeaSMDbPSYe0K'
  34. }
  35. };
  36. })
  37. .success(function(user, info) {
  38. expect(user).to.deep.equal({ id: '248289761001' });
  39. expect(info).to.be.undefined;
  40. expect(this.session).to.deep.equal({
  41. messages: []
  42. });
  43. done();
  44. })
  45. .error(done)
  46. .authenticate();
  47. }); // should verify address
  48. });