libeufin

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

commit 5888c5283bce2400d655cc9e29823f99a144b504
parent 5d3e7337b15bc8b10c42a93a08df3941e80ae259
Author: ms <ms@taler.net>
Date:   Thu, 14 Oct 2021 15:51:52 +0200

renaming

Diffstat:
Msandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt | 3+++
Mutil/src/main/kotlin/Config.kt | 8+++++++-
Mutil/src/main/kotlin/HTTP.kt | 5+++--
3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt @@ -463,6 +463,9 @@ val sandboxApp: Application.() -> Unit = { call.application.apply { if (adminPassword != null) { call.attributes.put(AttributeKey("adminPassword"), adminPassword) + /** + * When not given, the checker expects --no-auth to have been specified on the CLI. + */ } } } diff --git a/util/src/main/kotlin/Config.kt b/util/src/main/kotlin/Config.kt @@ -52,7 +52,13 @@ fun setLogLevel(logLevel: String?) { } } -internal fun <T : Any>ApplicationCall.getAttribute(name: String): T { +internal fun <T : Any>ApplicationCall.maybeAttribute(name: String): T? { + val key = AttributeKey<T>("name") + if (!this.attributes.contains(key)) return null + return this.attributes[key] +} + +internal fun <T : Any>ApplicationCall.ensureAttribute(name: String): T { val key = AttributeKey<T>("name") if (!this.attributes.contains(key)) throw internalServerError("Attribute $name not found along the call.") diff --git a/util/src/main/kotlin/HTTP.kt b/util/src/main/kotlin/HTTP.kt @@ -89,14 +89,15 @@ fun ApplicationRequest.getBaseUrl(): String { * environment. */ fun ApplicationRequest.basicAuth() { - val withAuth = this.call.getAttribute<Boolean>("withAuth") + val withAuth = this.call.ensureAttribute<Boolean>("withAuth") if (!withAuth) { logger.info("Authentication is disabled - assuming tests currently running.") return } val credentials = getHTTPBasicAuthCredentials(this) if (credentials.first == "admin") { - val adminPassword = this.call.getAttribute<String>("adminPassword") + // env must contain the admin password, because --with-auth is true. + val adminPassword = this.call.ensureAttribute<String>("adminPassword") if (credentials.second != adminPassword) throw unauthorized( "Admin authentication failed" )