@@ -9,6 +9,10 @@ import options from "./options";
99
1010let app : Application ;
1111
12+ function encodeCred ( password : string ) : string {
13+ return Buffer . from ( `dummy:${ password } ` ) . toString ( "base64" ) ;
14+ }
15+
1216describe ( "Auth" , ( ) => {
1317 beforeAll ( async ( ) => {
1418 const buildApp = ( await ( import ( "../../src/app.js" ) ) ) . default ;
@@ -72,4 +76,49 @@ describe("Auth", () => {
7276 . expect ( 200 ) ;
7377 } ) ;
7478 } ) ;
79+
80+ describe ( "Setup status endpoint" , ( ) => {
81+ it ( "returns totpEnabled: true when TOTP is enabled" , async ( ) => {
82+ cls . init ( ( ) => {
83+ options . setOption ( "mfaEnabled" , "true" ) ;
84+ options . setOption ( "mfaMethod" , "totp" ) ;
85+ options . setOption ( "totpVerificationHash" , "hi" ) ;
86+ } ) ;
87+ const response = await supertest ( app )
88+ . get ( "/api/setup/status" )
89+ . expect ( 200 ) ;
90+ expect ( response . body . totpEnabled ) . toBe ( true ) ;
91+ } ) ;
92+
93+ it ( "returns totpEnabled: false when TOTP is disabled" , async ( ) => {
94+ cls . init ( ( ) => {
95+ options . setOption ( "mfaEnabled" , "false" ) ;
96+ } ) ;
97+ const response = await supertest ( app )
98+ . get ( "/api/setup/status" )
99+ . expect ( 200 ) ;
100+ expect ( response . body . totpEnabled ) . toBe ( false ) ;
101+ } ) ;
102+ } ) ;
103+
104+ describe ( "checkCredentials TOTP enforcement" , ( ) => {
105+ beforeAll ( ( ) => {
106+ config . General . noAuthentication = false ;
107+ refreshAuth ( ) ;
108+ } ) ;
109+
110+ it ( "does not require TOTP token when TOTP is disabled" , async ( ) => {
111+ cls . init ( ( ) => {
112+ options . setOption ( "mfaEnabled" , "false" ) ;
113+ } ) ;
114+ // Will still fail with 401 due to wrong password, but NOT because of missing TOTP
115+ const response = await supertest ( app )
116+ . get ( "/api/setup/sync-seed" )
117+ . set ( "trilium-cred" , encodeCred ( "wrongpassword" ) )
118+ . expect ( 401 ) ;
119+ // The error should be about password, not TOTP
120+ expect ( response . text ) . toContain ( "Incorrect password" ) ;
121+ } ) ;
122+ } ) ;
75123} , 60_000 ) ;
124+
0 commit comments