mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	test(etapi): port basic-auth
This commit is contained in:
		| @@ -1,21 +0,0 @@ | ||||
| GET {{triliumHost}}/etapi/app-info | ||||
| Authorization: Basic etapi {{authToken}} | ||||
|  | ||||
| > {% | ||||
|     client.assert(response.status === 200); | ||||
|     client.assert(response.body.clipperProtocolVersion === "1.0"); | ||||
| %} | ||||
|  | ||||
| ### | ||||
|  | ||||
| GET {{triliumHost}}/etapi/app-info | ||||
| Authorization: Basic etapi wrong | ||||
|  | ||||
| > {% client.assert(response.status === 401); %} | ||||
|  | ||||
| ### | ||||
|  | ||||
| GET {{triliumHost}}/etapi/app-info | ||||
| Authorization: Basic wrong {{authToken}} | ||||
|  | ||||
| > {% client.assert(response.status === 401); %} | ||||
							
								
								
									
										41
									
								
								apps/server/spec/etapi/basic-auth.spec.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								apps/server/spec/etapi/basic-auth.spec.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,41 @@ | ||||
| import { Application } from "express"; | ||||
| import { beforeAll, describe, expect, it } from "vitest"; | ||||
| import supertest from "supertest"; | ||||
| import { login } from "./utils.js"; | ||||
| import config from "../../src/services/config.js"; | ||||
|  | ||||
| let app: Application; | ||||
| let token: string; | ||||
|  | ||||
| const USER = "etapi"; | ||||
| const URL = "/etapi/notes/root"; | ||||
|  | ||||
| describe("basic-auth", () => { | ||||
|     beforeAll(async () => { | ||||
|         config.General.noAuthentication = false; | ||||
|         const buildApp = (await (import("../../src/app.js"))).default; | ||||
|         app = await buildApp(); | ||||
|         token = await login(app); | ||||
|     }); | ||||
|  | ||||
|     it("auth token works", async () => { | ||||
|         const response = await supertest(app) | ||||
|             .get(URL) | ||||
|             .auth(USER, token, { "type": "basic"}) | ||||
|             .expect(200); | ||||
|     }); | ||||
|  | ||||
|     it("rejects wrong password", async () => { | ||||
|         const response = await supertest(app) | ||||
|             .get(URL) | ||||
|             .auth(USER, "wrong", { "type": "basic"}) | ||||
|             .expect(401); | ||||
|     }); | ||||
|  | ||||
|     it("rejects wrong user", async () => { | ||||
|         const response = await supertest(app) | ||||
|             .get(URL) | ||||
|             .auth("wrong", token, { "type": "basic"}) | ||||
|             .expect(401); | ||||
|     }); | ||||
| }); | ||||
| @@ -12,4 +12,5 @@ export async function login(app: Application) { | ||||
|         .expect(201); | ||||
|     const token = response.body.authToken; | ||||
|     expect(token).toBeTruthy(); | ||||
|     return token; | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user