add tests for specialized exceptions
This commit is contained in:
		@@ -27,9 +27,12 @@ async function start_server () {
 | 
				
			|||||||
      return user;
 | 
					      return user;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return null;
 | 
					    return null;
 | 
				
			||||||
  }));
 | 
					  }, [
 | 
				
			||||||
 | 
					    /noauthreg/u,
 | 
				
			||||||
 | 
					    { method: 'POST', regex: /noauthobj/u }
 | 
				
			||||||
 | 
					  ]));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  app.get ('/', (req, res) => {
 | 
					  app.use ((req, res) => {
 | 
				
			||||||
    res.status (consts.http.status_ok)
 | 
					    res.status (consts.http.status_ok)
 | 
				
			||||||
      .end ('foo');
 | 
					      .end ('foo');
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -29,10 +29,35 @@ test ('login', async (t) => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  const resp = await fetch ('http://localhost:3000', { headers: { session } });
 | 
					  const resp = await fetch ('http://localhost:3000', { headers: { session } });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  t.is (await resp.status, consts.http.status_ok);
 | 
					  t.is (resp.status, consts.http.status_ok);
 | 
				
			||||||
  t.is (await resp.text (), 'foo');
 | 
					  t.is (await resp.text (), 'foo');
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					test ('allow access to excluded paths', async (t) => {
 | 
				
			||||||
 | 
					  const resp = await fetch ('http://localhost:3000/noauthreg');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  t.is (resp.status, consts.http.status_ok);
 | 
				
			||||||
 | 
					  t.is (await resp.text (), 'foo');
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					test ('allow access to excluded paths with correct method', async (t) => {
 | 
				
			||||||
 | 
					  const resp = await fetch (
 | 
				
			||||||
 | 
					    'http://localhost:3000/noauthobj',
 | 
				
			||||||
 | 
					    { method: 'POST' }
 | 
				
			||||||
 | 
					  );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  t.is (resp.status, consts.http.status_ok);
 | 
				
			||||||
 | 
					  t.is (await resp.text (), 'foo');
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					test ('reject access to excluded paths with wrong method', async (t) => {
 | 
				
			||||||
 | 
					  const resp = await fetch (
 | 
				
			||||||
 | 
					    'http://localhost:3000/noauthobj'
 | 
				
			||||||
 | 
					  );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  t.is (resp.status, consts.http.status_unauthorized);
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
test ('reject invalid user', async (t) => {
 | 
					test ('reject invalid user', async (t) => {
 | 
				
			||||||
  await t.throwsAsync (client.login (
 | 
					  await t.throwsAsync (client.login (
 | 
				
			||||||
    'foo',
 | 
					    'foo',
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user