You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dlab.apache.org by bh...@apache.org on 2019/12/10 13:40:51 UTC

[incubator-dlab] branch feature-integration-tests updated (aaa2c24 -> 99d3364)

This is an automated email from the ASF dual-hosted git repository.

bhliva pushed a change to branch feature-integration-tests
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git.


 discard aaa2c24  DLAB-000 integration tests updated
     new 99d3364  DLAB-000 integration tests updated

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (aaa2c24)
            \
             N -- N -- N   refs/heads/feature-integration-tests (99d3364)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../src/test/java/dlab/endpoint/EndpointSteps.java                       | 1 -
 1 file changed, 1 deletion(-)


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@dlab.apache.org
For additional commands, e-mail: commits-help@dlab.apache.org


[incubator-dlab] 01/01: DLAB-000 integration tests updated

Posted by bh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

bhliva pushed a commit to branch feature-integration-tests
in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git

commit 99d3364a0150fd8deeccc6d157c697cd12462f34
Author: bhliva <bo...@epam.com>
AuthorDate: Tue Dec 10 15:36:53 2019 +0200

    DLAB-000 integration tests updated
---
 .../java/org/apache/dlab/util/PropertyHelper.java  |  2 +
 .../src/test/java/dlab/Constants.java              |  4 +-
 .../src/test/java/dlab/endpoint/EndpointSteps.java |  5 ++-
 .../src/test/java/dlab/login/LoginSteps.java       | 44 ----------------------
 .../src/test/java/dlab/util/KeycloakUtil.java      | 38 +++++++++++++++++++
 .../src/test/resources/config.properties           |  9 ++++-
 .../src/test/resources/dlab/login.feature          | 12 ------
 7 files changed, 53 insertions(+), 61 deletions(-)

diff --git a/integration-tests-cucumber/src/main/java/org/apache/dlab/util/PropertyHelper.java b/integration-tests-cucumber/src/main/java/org/apache/dlab/util/PropertyHelper.java
index 48d7cca..6b4a60a 100644
--- a/integration-tests-cucumber/src/main/java/org/apache/dlab/util/PropertyHelper.java
+++ b/integration-tests-cucumber/src/main/java/org/apache/dlab/util/PropertyHelper.java
@@ -2,6 +2,7 @@ package org.apache.dlab.util;
 
 import java.io.FileInputStream;
 import java.io.InputStream;
+import java.util.Optional;
 import java.util.Properties;
 
 public class PropertyHelper {
@@ -10,6 +11,7 @@ public class PropertyHelper {
 
 	static {
 		PROPERTIES = new Properties();
+
 		try (InputStream inputStream = new FileInputStream(System.getProperty("config.file"))) {
 			PROPERTIES.load(inputStream);
 		} catch (Exception e) {
diff --git a/integration-tests-cucumber/src/test/java/dlab/Constants.java b/integration-tests-cucumber/src/test/java/dlab/Constants.java
index 4e30e99..a27ed77 100644
--- a/integration-tests-cucumber/src/test/java/dlab/Constants.java
+++ b/integration-tests-cucumber/src/test/java/dlab/Constants.java
@@ -1,5 +1,7 @@
 package dlab;
 
+import org.apache.dlab.util.PropertyHelper;
+
 public interface Constants {
-	String API_URI = "https://localhost:8443/api/";
+	String API_URI = PropertyHelper.read("dlab.api.base.uri");
 }
diff --git a/integration-tests-cucumber/src/test/java/dlab/endpoint/EndpointSteps.java b/integration-tests-cucumber/src/test/java/dlab/endpoint/EndpointSteps.java
index e66fc33..624b1ca 100644
--- a/integration-tests-cucumber/src/test/java/dlab/endpoint/EndpointSteps.java
+++ b/integration-tests-cucumber/src/test/java/dlab/endpoint/EndpointSteps.java
@@ -7,6 +7,7 @@ import cucumber.api.java.en.And;
 import cucumber.api.java.en.Given;
 import cucumber.api.java.en.Then;
 import cucumber.api.java.en.When;
+import dlab.util.KeycloakUtil;
 import org.apache.dlab.dto.EndpointDTO;
 import org.apache.dlab.mongo.MongoDBHelper;
 import org.apache.dlab.util.JacksonMapper;
@@ -29,7 +30,7 @@ public class EndpointSteps {
 		this.name = name;
 		request = given().body(JacksonMapper.marshall(new EndpointDTO(name, uri, account, tag)))
 				.auth()
-				.oauth2("token123")
+				.oauth2(KeycloakUtil.getToken())
 				.contentType(ContentType.JSON);
 
 	}
@@ -92,6 +93,6 @@ public class EndpointSteps {
 	private RequestSpecification authenticatedRequest() {
 		return given()
 				.auth()
-				.oauth2("token123");
+				.oauth2(KeycloakUtil.getToken());
 	}
 }
diff --git a/integration-tests-cucumber/src/test/java/dlab/login/LoginSteps.java b/integration-tests-cucumber/src/test/java/dlab/login/LoginSteps.java
deleted file mode 100644
index 32b29cb..0000000
--- a/integration-tests-cucumber/src/test/java/dlab/login/LoginSteps.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package dlab.login;
-
-import com.jayway.restassured.http.ContentType;
-import com.jayway.restassured.response.Response;
-import com.jayway.restassured.specification.RequestSpecification;
-import cucumber.api.java.en.Given;
-import cucumber.api.java.en.Then;
-import cucumber.api.java.en.When;
-import gherkin.deps.com.google.gson.JsonObject;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-
-import static com.jayway.restassured.RestAssured.given;
-import static dlab.Constants.API_URI;
-import static org.hamcrest.core.IsEqual.equalTo;
-import static org.junit.Assert.assertThat;
-
-public class LoginSteps {
-
-
-	private static final String LOGIN_RESOURCE_PATH = API_URI + "user/login";
-	private RequestSpecification request;
-	private Response response;
-
-	@Given("User try to login to Dlab with {string} and {string}")
-	public void userProvidedLoginAndPassword(String username, String password) {
-		JsonObject jsonObject = new JsonObject();
-		jsonObject.addProperty("username", username);
-		jsonObject.addProperty("password", password);
-		request = given().body(jsonObject.toString()).contentType(ContentType.JSON);
-	}
-
-	@When("user try to login")
-	public void userTryToLogin() throws URISyntaxException {
-		response = request.post(new URI(LOGIN_RESOURCE_PATH));
-	}
-
-	@Then("response code is {string}")
-	public void responseCodeIs(String status) {
-		assertThat(response.getStatusCode(), equalTo(Integer.valueOf(status)));
-
-	}
-}
diff --git a/integration-tests-cucumber/src/test/java/dlab/util/KeycloakUtil.java b/integration-tests-cucumber/src/test/java/dlab/util/KeycloakUtil.java
new file mode 100644
index 0000000..0b4fe2c
--- /dev/null
+++ b/integration-tests-cucumber/src/test/java/dlab/util/KeycloakUtil.java
@@ -0,0 +1,38 @@
+package dlab.util;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import org.apache.dlab.util.PropertyHelper;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static com.jayway.restassured.RestAssured.given;
+
+public class KeycloakUtil {
+
+	@Getter
+	@NoArgsConstructor
+	@JsonIgnoreProperties(ignoreUnknown = true)
+	private static class KeyckloakResponse {
+		@JsonProperty("access_token")
+		private String token;
+	}
+
+	public static final String TOKEN_URI = String.format("%s/realms/%s/protocol/openid-connect/token",
+			PropertyHelper.read("keycloak.serverUrl"), PropertyHelper.read("keycloak.realm"));
+
+	public static String getToken() {
+		return given().formParameters(getFormParams()).post(TOKEN_URI).getBody().as(KeyckloakResponse.class).getToken();
+	}
+
+	private static Map<String, ?> getFormParams() {
+		Map<String, String> params = new HashMap<>();
+		params.put("grant_type", "client_credentials");
+		params.put("client_id", PropertyHelper.read("keycloak.clientId"));
+		params.put("client_secret", PropertyHelper.read("keycloak.clientSecret"));
+		return params;
+	}
+}
diff --git a/integration-tests-cucumber/src/test/resources/config.properties b/integration-tests-cucumber/src/test/resources/config.properties
index 5cfad3c..49933a9 100644
--- a/integration-tests-cucumber/src/test/resources/config.properties
+++ b/integration-tests-cucumber/src/test/resources/config.properties
@@ -1,2 +1,7 @@
-mongo.connection.string=mongodb://localhost:27017/DLAB
-mongo.db.name=DLAB
\ No newline at end of file
+dlab.api.base.uri=<API_URI>
+mongo.connection.string=<MONGO_CONNECTION_STRING>
+mongo.db.name=<DB_NAME>
+keycloak.serverUrl=<KEYCLOAK_SERVER_URL>
+keycloak.realm=<REALM>
+keycloak.clientId=<KEYCLOAK_CLIENT_ID>
+keycloak.clientSecret=<KEYCLOAK_CLIENT_SECRET>
\ No newline at end of file
diff --git a/integration-tests-cucumber/src/test/resources/dlab/login.feature b/integration-tests-cucumber/src/test/resources/dlab/login.feature
deleted file mode 100644
index 493a51e..0000000
--- a/integration-tests-cucumber/src/test/resources/dlab/login.feature
+++ /dev/null
@@ -1,12 +0,0 @@
-Feature: DLab login API
-  Used to check DLab login flow
-
-  Scenario Outline: User try to login to DLab
-    Given User try to login to Dlab with "<username>" and "<password>"
-    When user try to login
-    Then response code is "<status>"
-
-    Examples:
-      | username       | password | status |
-      | test           | pass     | 200    |
-      | not_valid_user | pass     | 401    |
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@dlab.apache.org
For additional commands, e-mail: commits-help@dlab.apache.org