소스 검색

Add tests.

Jared Hanson 3 년 전
부모
커밋
a604339e17
1개의 변경된 파일39개의 추가작업 그리고 2개의 파일을 삭제
  1. 39 2
      test/strategy.test.js

+ 39 - 2
test/strategy.test.js

@@ -173,7 +173,44 @@ describe('Strategy', function() {
       .authenticate();
   }); // should fail when message is not yet valid
   
-  it('should fail when address is missing from message', function(done) {
+  it('should fail when signature is invalid', function(done) {
+    chai.passport.use(new Strategy(function(address, cb) {
+      expect(address).to.equal('0xCC6F4DF4B758C4DE3203e8842E2d8CAc564D7758');
+      return cb(null, { id: '248289761001' });
+    }))
+      .request(function(req) {
+        req.connection = {};
+        req.headers.host = 'localhost:3000';
+        req.body = {
+          message: 'localhost:3000 wants you to sign in with your Ethereum account:\n' +
+            '0xCC6F4DF4B758C4DE3203e8842E2d8CAc564D7758\n' +
+            '\n' +
+            'Sign in with Ethereum to the app.\n' +
+            '\n' +
+            'URI: http://localhost:3000\n' +
+            'Version: 1\n' +
+            'Chain ID: 1\n' +
+            'Nonce: VjglqeaSMDbPSYe0K\n' +
+            'Issued At: 2022-06-07T16:28:10.957Z',
+          signature: '0xF303d03782c532e2371e3d75a8b2b093c2dceb5faed5d07d6506be96be783245515db6ad55ad6d598ebdf1f7e1c5cb0d24e7147bbad47d3b9d8dfbcfab2ddcc71b'
+        };
+        req.session = {
+          messages: [],
+          'ethereum:siwe': {
+            nonce: 'VjglqeaSMDbPSYe0K'
+          }
+        };
+      })
+      .fail(function(challenge, status) {
+        expect(challenge).to.deep.equal({ message: 'Invalid signature.: 0x09967aCB4912a3efDb66039b8BC8ABb202a0f3E4 !== 0xCC6F4DF4B758C4DE3203e8842E2d8CAc564D7758' });
+        expect(status).to.equal(403);
+        done();
+      })
+      .error(done)
+      .authenticate();
+  }); // should fail when signature is invalid
+  
+  it('should fail when message is malformed (missing message)', function(done) {
     chai.passport.use(new Strategy(function(address, cb) {
       expect(address).to.equal('0xCC6F4DF4B758C4DE3203e8842E2d8CAc564D7758');
       return cb(null, { id: '248289761001' });
@@ -207,7 +244,7 @@ describe('Strategy', function() {
       })
       .error(done)
       .authenticate();
-  }); // should fail when address is missing from message
+  }); // should fail when message is malformed (missing message)
   
   it('should fail when missing message', function(done) {
     chai.passport.use(new Strategy(function(address, cb) {