libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

ObservabilityTest.kt (1869B)


      1 /*
      2  * This file is part of LibEuFin.
      3  * Copyright (C) 2025 Taler Systems S.A.
      4 
      5  * LibEuFin is free software; you can redistribute it and/or modify
      6  * it under the terms of the GNU Affero General Public License as
      7  * published by the Free Software Foundation; either version 3, or
      8  * (at your option) any later version.
      9 
     10  * LibEuFin is distributed in the hope that it will be useful, but
     11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
     12  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General
     13  * Public License for more details.
     14 
     15  * You should have received a copy of the GNU Affero General Public
     16  * License along with LibEuFin; see the file COPYING.  If not, see
     17  * <http://www.gnu.org/licenses/>
     18  */
     19 
     20 import io.ktor.http.*
     21 import io.ktor.client.request.*
     22 import org.junit.Test
     23 import tech.libeufin.bank.*
     24 import tech.libeufin.common.*
     25 import tech.libeufin.common.test.*
     26 
     27 class ObservabilityApiTest {
     28     // GET /taler-observability/config
     29     @Test
     30     fun config() = bankSetup {
     31         client.get("/taler-observability/config").assertOkJson<TalerObservabilityConfig>()
     32     }
     33 
     34     // GET /taler-observability/metrics
     35     @Test
     36     fun metrics() = bankSetup { db ->
     37         authRoutine(HttpMethod.Get, "/taler-observability/metrics", requireAdmin = true)
     38         client.getAdmin("/taler-observability/metrics").assertOk()
     39 
     40           // Check observability token
     41         val response = client.post("/accounts/admin/token") {
     42             pwAuth()
     43             json {
     44                 "scope" to "observability"
     45                 "duration" to obj {
     46                     "d_us" to "forever"
     47                 }
     48             }
     49         }.assertOkJson<TokenSuccessResponse>()
     50         client.get("/taler-observability/metrics") {
     51             headers[HttpHeaders.Authorization] = "Bearer ${response.access_token}"
     52         }.assertOk()
     53     }
     54 }