From 11cabbff09dd069e680c1ca0b43feccf02b91cd5 Mon Sep 17 00:00:00 2001 From: hawknewton Date: Thu, 21 May 2020 15:37:46 -0700 Subject: [PATCH 1/7] Add keycloak versions to acceptance testing --- .circleci/config.yml | 101 ++++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 50 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index d0e129203..495dff933 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,13 +1,29 @@ -version: 2 +version: 2.1 workflows: - version: 2 test: jobs: - - test-7.0.1 - - test-8.0.1 + - test: + matrix: + parameters: + keycloak-version: + - '10.0.1' + - '10.0.0' + - '9.0.3' + - '9.0.2' + - '9.0.0' + - '8.0.2' + - '8.0.1' + - '8.0.0' + - '7.0.1' + - '7.0.0' + - '6.0.1' + - '6.0.0' + - '5.0.0' + - '4.8.3' release: jobs: - - test-8.0.1: + - test: + keycloak-version: '8.0.1' filters: tags: only: /\d+\.\d+\.\d+(-rc.\d+)?/ @@ -15,35 +31,27 @@ workflows: ignore: /.*/ - build-and-release: requires: - - test-8.0.1 - filters: - tags: - only: /\d+\.\d+\.\d+(-rc.\d+)?/ - branches: - ignore: /.*/ + - test defaults: go_image: &go_image - image: circleci/golang:1.13.5 - test_env: &test_env - GO111MODULE: "on" - KEYCLOAK_CLIENT_ID: "terraform" - KEYCLOAK_CLIENT_SECRET: "884e0f95-0f42-4a63-9b1f-94274655669e" - KEYCLOAK_CLIENT_TIMEOUT: "5" - KEYCLOAK_URL: "http://localhost:8080" - KEYCLOAK_REALM: "master" - KEYCLOAK_TEST_PASSWORD_GRANT: "true" - - keycloak_env: &keycloak_env - command: ["-b", "0.0.0.0", "-Dkeycloak.profile.feature.upload_scripts=enabled"] - environment: - DB_VENDOR: H2 - KEYCLOAK_LOGLEVEL: DEBUG - KEYCLOAK_USER: keycloak - KEYCLOAK_PASSWORD: password +jobs: + test: + parameters: + keycloak-version: + type: string + docker: + - <<: *go_image + - image: jboss/keycloak:<< parameters.keycloak-version >> + command: ["-b", "0.0.0.0", "-Dkeycloak.profile.feature.upload_scripts=enabled"] + environment: + DB_VENDOR: H2 + KEYCLOAK_LOGLEVEL: DEBUG + KEYCLOAK_USER: keycloak + KEYCLOAK_PASSWORD: password - testacc_job: &testacc_job working_directory: /go/src/github.com/mrparkers/terraform-provider-keycloak steps: - checkout @@ -51,6 +59,8 @@ defaults: keys: - go-cache-{{ checksum "go.sum" }} - run: go mod download + - run: go get github.com/jstemmer/go-junit-report + - run: mkdir $TEST_RESULTS - save_cache: key: go-cache-{{ checksum "go.sum" }} paths: @@ -59,29 +69,20 @@ defaults: command: | ./scripts/wait-for-local-keycloak.sh ./scripts/create-terraform-client.sh - make testacc - -jobs: - test-7.0.1: - docker: - - <<: *go_image - - image: jboss/keycloak:7.0.1 - <<: *keycloak_env - <<: *testacc_job - environment: - <<: *test_env - KEYCLOAK_VERSION: "7.0.1" - - - test-8.0.1: - docker: - - <<: *go_image - - image: jboss/keycloak:8.0.1 - <<: *keycloak_env - <<: *testacc_job + trap "go-junit-report <${TEST_RESULTS}/go-test.out > ${TEST_RESULTS}/go-test-report.xml" EXIT + make testacc | tee ${TEST_RESULTS}/go-test.out + - store_test_results: + path: /tmp/test-results environment: - <<: *test_env - KEYCLOAK_VERSION: "8.0.1" + GO111MODULE: "on" + KEYCLOAK_CLIENT_ID: "terraform" + KEYCLOAK_CLIENT_SECRET: "884e0f95-0f42-4a63-9b1f-94274655669e" + KEYCLOAK_CLIENT_TIMEOUT: "5" + KEYCLOAK_URL: "http://localhost:8080" + KEYCLOAK_REALM: "master" + KEYCLOAK_TEST_PASSWORD_GRANT: "true" + KEYCLOAK_VERSION: "<< parameters.keycloak-version >>" + TEST_RESULTS: /tmp/test-results build-and-release: From c297c9319bf1e80b759189d5aaff78ae04e176e4 Mon Sep 17 00:00:00 2001 From: hawknewton Date: Fri, 22 May 2020 11:27:44 -0700 Subject: [PATCH 2/7] Remove 4.8.3 from acceptance testing --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 495dff933..dbdd1ebea 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -6,6 +6,7 @@ workflows: matrix: parameters: keycloak-version: + # 4.8.3 doesn't have a docker image - '10.0.1' - '10.0.0' - '9.0.3' @@ -19,7 +20,6 @@ workflows: - '6.0.1' - '6.0.0' - '5.0.0' - - '4.8.3' release: jobs: - test: From 8547787b6be21d54273a1354654e2c7afe5e6fd3 Mon Sep 17 00:00:00 2001 From: hawknewton Date: Fri, 22 May 2020 13:18:06 -0700 Subject: [PATCH 3/7] Add 4.8.3.Final to circle --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index dbdd1ebea..aa0c7ec29 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -20,6 +20,7 @@ workflows: - '6.0.1' - '6.0.0' - '5.0.0' + - '4.8.3.Final' release: jobs: - test: From 94ed8ec38cbc048e151345be6c05aa00cdc86cf2 Mon Sep 17 00:00:00 2001 From: Michael Parker Date: Wed, 27 May 2020 10:30:46 -0500 Subject: [PATCH 4/7] fix missing client secret for password grant refresh --- keycloak/keycloak_client.go | 53 +++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/keycloak/keycloak_client.go b/keycloak/keycloak_client.go index 570b1ddbb..17dc8ab08 100644 --- a/keycloak/keycloak_client.go +++ b/keycloak/keycloak_client.go @@ -105,21 +105,7 @@ func NewKeycloakClient(baseUrl, clientId, clientSecret, realm, username, passwor func (keycloakClient *KeycloakClient) login() error { accessTokenUrl := fmt.Sprintf(tokenUrl, keycloakClient.baseUrl, keycloakClient.realm) - accessTokenData := url.Values{} - accessTokenData.Set("client_id", keycloakClient.clientCredentials.ClientId) - accessTokenData.Set("grant_type", keycloakClient.clientCredentials.GrantType) - - if keycloakClient.clientCredentials.GrantType == "password" { - accessTokenData.Set("username", keycloakClient.clientCredentials.Username) - accessTokenData.Set("password", keycloakClient.clientCredentials.Password) - - if keycloakClient.clientCredentials.ClientSecret != "" { - accessTokenData.Set("client_secret", keycloakClient.clientCredentials.ClientSecret) - } - - } else if keycloakClient.clientCredentials.GrantType == "client_credentials" { - accessTokenData.Set("client_secret", keycloakClient.clientCredentials.ClientSecret) - } + accessTokenData := keycloakClient.getAuthenticationFormData() log.Printf("[DEBUG] Login request: %s", accessTokenData.Encode()) @@ -153,23 +139,14 @@ func (keycloakClient *KeycloakClient) login() error { func (keycloakClient *KeycloakClient) refresh() error { refreshTokenUrl := fmt.Sprintf(tokenUrl, keycloakClient.baseUrl, keycloakClient.realm) - refreshTokenData := url.Values{} - refreshTokenData.Set("client_id", keycloakClient.clientCredentials.ClientId) - refreshTokenData.Set("grant_type", keycloakClient.clientCredentials.GrantType) - - if keycloakClient.clientCredentials.GrantType == "password" { - refreshTokenData.Set("username", keycloakClient.clientCredentials.Username) - refreshTokenData.Set("password", keycloakClient.clientCredentials.Password) - } else if keycloakClient.clientCredentials.GrantType == "client_credentials" { - refreshTokenData.Set("client_secret", keycloakClient.clientCredentials.ClientSecret) - } + refreshTokenData := keycloakClient.getAuthenticationFormData() log.Printf("[DEBUG] Refresh request: %s", refreshTokenData.Encode()) - accessTokenRequest, _ := http.NewRequest(http.MethodPost, refreshTokenUrl, strings.NewReader(refreshTokenData.Encode())) - accessTokenRequest.Header.Set("Content-Type", "application/x-www-form-urlencoded") + refreshTokenRequest, _ := http.NewRequest(http.MethodPost, refreshTokenUrl, strings.NewReader(refreshTokenData.Encode())) + refreshTokenRequest.Header.Set("Content-Type", "application/x-www-form-urlencoded") - refreshTokenResponse, err := keycloakClient.httpClient.Do(accessTokenRequest) + refreshTokenResponse, err := keycloakClient.httpClient.Do(refreshTokenRequest) if err != nil { return err } @@ -200,6 +177,26 @@ func (keycloakClient *KeycloakClient) refresh() error { return nil } +func (keycloakClient *KeycloakClient) getAuthenticationFormData() url.Values { + authenticationFormData := url.Values{} + authenticationFormData.Set("client_id", keycloakClient.clientCredentials.ClientId) + authenticationFormData.Set("grant_type", keycloakClient.clientCredentials.GrantType) + + if keycloakClient.clientCredentials.GrantType == "password" { + authenticationFormData.Set("username", keycloakClient.clientCredentials.Username) + authenticationFormData.Set("password", keycloakClient.clientCredentials.Password) + + if keycloakClient.clientCredentials.ClientSecret != "" { + authenticationFormData.Set("client_secret", keycloakClient.clientCredentials.ClientSecret) + } + + } else if keycloakClient.clientCredentials.GrantType == "client_credentials" { + authenticationFormData.Set("client_secret", keycloakClient.clientCredentials.ClientSecret) + } + + return authenticationFormData +} + func (keycloakClient *KeycloakClient) addRequestHeaders(request *http.Request) { tokenType := keycloakClient.clientCredentials.TokenType accessToken := keycloakClient.clientCredentials.AccessToken From 139a271bfcb8c1eeaeae742bf64597dcfd93add3 Mon Sep 17 00:00:00 2001 From: hawknewton Date: Wed, 27 May 2020 10:19:48 -0700 Subject: [PATCH 5/7] Remove outdated versions from Circle run --- .circleci/config.yml | 7 ------- 1 file changed, 7 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index aa0c7ec29..060d431fd 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -8,17 +8,10 @@ workflows: keycloak-version: # 4.8.3 doesn't have a docker image - '10.0.1' - - '10.0.0' - '9.0.3' - - '9.0.2' - - '9.0.0' - '8.0.2' - - '8.0.1' - - '8.0.0' - '7.0.1' - - '7.0.0' - '6.0.1' - - '6.0.0' - '5.0.0' - '4.8.3.Final' release: From 52e3c9c6c94388834c580e2364115fa0199ecb4a Mon Sep 17 00:00:00 2001 From: hawknewton Date: Mon, 1 Jun 2020 12:29:29 -0700 Subject: [PATCH 6/7] Truncate non-semver server versions --- provider/test_utils.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/provider/test_utils.go b/provider/test_utils.go index dc5ff5337..9c4630979 100644 --- a/provider/test_utils.go +++ b/provider/test_utils.go @@ -6,6 +6,7 @@ import ( "github.com/mrparkers/terraform-provider-keycloak/keycloak" "math/rand" "os" + "regexp" "strings" "testing" "time" @@ -86,7 +87,11 @@ func keycloakVersionIsGreaterThanOrEqualTo(keycloakClient *keycloak.KeycloakClie if err != nil { return false, fmt.Errorf("/serverInfo endpoint retuned an error, server Keycloak version could not be determined: %s", err) } - keycloakServerInfoVersion, err = version.NewVersion(serverInfo.SystemInfo.ServerVersion) + + regex := regexp.MustCompile(`^(\d+\.\d+\.\d+)`) + semver := regex.FindStringSubmatch(serverInfo.SystemInfo.ServerVersion)[0] + + keycloakServerInfoVersion, err = version.NewVersion(semver) if err != nil { return false, fmt.Errorf("/serverInfo endpoint retuned an unreadable version, server Keycloak version could not be determined: %s", err) } From b7c239f65d231290f5383da61b8290f0166aa9fd Mon Sep 17 00:00:00 2001 From: hawknewton Date: Mon, 1 Jun 2020 14:26:37 -0700 Subject: [PATCH 7/7] Remove comment --- .circleci/config.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 060d431fd..2a243e9ab 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -6,7 +6,6 @@ workflows: matrix: parameters: keycloak-version: - # 4.8.3 doesn't have a docker image - '10.0.1' - '9.0.3' - '8.0.2'