mirror of
				https://codeberg.org/yeentown/barkey.git
				synced 2025-11-04 15:34:13 +00:00 
			
		
		
		
	[Test] Add some auth tests
This commit is contained in:
		
							parent
							
								
									174cd3e97c
								
							
						
					
					
						commit
						03732b66c8
					
				
					 1 changed files with 39 additions and 0 deletions
				
			
		
							
								
								
									
										39
									
								
								test/api.js
									
										
									
									
									
								
							
							
						
						
									
										39
									
								
								test/api.js
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -924,6 +924,37 @@ describe('API', () => {
 | 
			
		|||
			});
 | 
			
		||||
		}));
 | 
			
		||||
	});
 | 
			
		||||
 | 
			
		||||
	describe('auth/session/generate', () => {
 | 
			
		||||
		it('認証セッションを作成できる', () => new Promise(async (done) => {
 | 
			
		||||
			const app = await insertApp();
 | 
			
		||||
			request('/auth/session/generate', {
 | 
			
		||||
				app_secret: app.secret
 | 
			
		||||
			}).then(res => {
 | 
			
		||||
				res.should.have.status(200);
 | 
			
		||||
				res.body.should.be.a('object');
 | 
			
		||||
				res.body.should.have.property('token');
 | 
			
		||||
				res.body.should.have.property('url');
 | 
			
		||||
				done();
 | 
			
		||||
			});
 | 
			
		||||
		}));
 | 
			
		||||
 | 
			
		||||
		it('app_secret 無しで怒られる', () => new Promise(async (done) => {
 | 
			
		||||
			request('/auth/session/generate', {}).then(res => {
 | 
			
		||||
				res.should.have.status(400);
 | 
			
		||||
				done();
 | 
			
		||||
			});
 | 
			
		||||
		}));
 | 
			
		||||
 | 
			
		||||
		it('誤った app secret で怒られる', () => new Promise(async (done) => {
 | 
			
		||||
			request('/auth/session/generate', {
 | 
			
		||||
				app_secret: 'kyoppie'
 | 
			
		||||
			}).then(res => {
 | 
			
		||||
				res.should.have.status(400);
 | 
			
		||||
				done();
 | 
			
		||||
			});
 | 
			
		||||
		}));
 | 
			
		||||
	});
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
async function insertSakurako(opts) {
 | 
			
		||||
| 
						 | 
				
			
			@ -955,3 +986,11 @@ async function insertDriveFolder(opts) {
 | 
			
		|||
		name: 'my folder'
 | 
			
		||||
	}), opts);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function insertApp(opts) {
 | 
			
		||||
	return await db.get('apps').insert(Object.assign({
 | 
			
		||||
		name: 'my app',
 | 
			
		||||
		secret: 'mysecret'
 | 
			
		||||
	}), opts);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue