From c7f12f53c71a92d031338b41c1d09b4c95032278 Mon Sep 17 00:00:00 2001 From: Greg Schueler Date: Mon, 9 Oct 2023 13:11:29 -0700 Subject: [PATCH] fix #465: user+pass auth url incorrect if API version specified in URL --- .../org/rundeck/client/RundeckClient.java | 3 +-- .../rundeck/client/RundeckClientSpec.groovy | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/rd-api-client/src/main/java/org/rundeck/client/RundeckClient.java b/rd-api-client/src/main/java/org/rundeck/client/RundeckClient.java index d7c113ed..020e72cc 100644 --- a/rd-api-client/src/main/java/org/rundeck/client/RundeckClient.java +++ b/rd-api-client/src/main/java/org/rundeck/client/RundeckClient.java @@ -246,8 +246,7 @@ private static void buildFormAuth( cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL); builder.cookieJar(new JavaNetCookieJar(cookieManager)); - - String postUrl = parse + String postUrl = HttpUrl.parse(appBaseUrl) .newBuilder() .addPathSegment( System.getProperty( diff --git a/rd-cli-tool/src/test/groovy/org/rundeck/client/RundeckClientSpec.groovy b/rd-cli-tool/src/test/groovy/org/rundeck/client/RundeckClientSpec.groovy index ddea98da..fa79a671 100644 --- a/rd-cli-tool/src/test/groovy/org/rundeck/client/RundeckClientSpec.groovy +++ b/rd-cli-tool/src/test/groovy/org/rundeck/client/RundeckClientSpec.groovy @@ -16,6 +16,7 @@ package org.rundeck.client +import org.rundeck.client.util.FormAuthInterceptor import spock.lang.Specification /** @@ -50,6 +51,30 @@ class RundeckClientSpec extends Specification { 'https' | _ } + def "password auth with API vers has correct auth url"() { + given: + def root = 'https://example.com' + when: + + def builder = RundeckClient.builder(). + baseUrl(root + basePath). + passwordAuth('user1', 'pass1') + + then: + builder.okhttp.interceptors().size() == 1 + def formAuth = builder.okhttp.interceptors().get(0) + formAuth instanceof FormAuthInterceptor + formAuth.baseUrl == (root + expectedBase) + formAuth.j_security_url == (root + expectedSecurity) + + where: + basePath | expectedBase | expectedSecurity + "/" | "/" | "/j_security_check" + "/api/19" | "/" | "/j_security_check" + "/context" | "/context/" | "/context/j_security_check" + "/context/api/19" | "/context/" | "/context/j_security_check" + } + def "create token valid"() { given: def token = 'abc'