Skip to content

Commit c16d99f

Browse files
author
Anders Breid
authored
Merge 2.0.0-maintanance with master (#406)
See 2.0.1 to 2.1.0 release notes.
1 parent 43fb7f9 commit c16d99f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2339
-426
lines changed

pom.xml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<modelVersion>4.0.0</modelVersion>
77
<groupId>com.github.ericsson</groupId>
88
<artifactId>eiffel-intelligence</artifactId>
9-
<version>2.0.0</version>
9+
<version>3.0.0-SNAPSHOT</version>
1010
<packaging>war</packaging>
1111

1212
<parent>
@@ -107,6 +107,12 @@
107107
<version>${springBootVersion}</version>
108108
</dependency>
109109

110+
<dependency>
111+
<groupId>com.github.ulisesbocchio</groupId>
112+
<artifactId>jasypt-spring-boot-starter</artifactId>
113+
<version>2.1.2</version>
114+
</dependency>
115+
110116
<dependency>
111117
<groupId>org.springframework.boot</groupId>
112118
<artifactId>spring-boot-starter-amqp</artifactId>
@@ -379,6 +385,12 @@
379385
<groupId>com.github.java-json-tools</groupId>
380386
<artifactId>json-schema-validator</artifactId>
381387
<version>2.2.8</version>
388+
<exclusions>
389+
<exclusion>
390+
<groupId>javax.mail</groupId>
391+
<artifactId>mailapi</artifactId>
392+
</exclusion>
393+
</exclusions>
382394
</dependency>
383395
</dependencies>
384396

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
package com.ericsson.ei.encryption;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertTrue;
5+
import static org.mockserver.model.HttpRequest.request;
6+
import static org.mockserver.model.HttpResponse.response;
7+
import static org.slf4j.LoggerFactory.getLogger;
8+
9+
import java.io.IOException;
10+
import java.util.ArrayList;
11+
import java.util.List;
12+
import java.util.concurrent.TimeUnit;
13+
14+
import org.json.JSONObject;
15+
import org.junit.Ignore;
16+
import org.mockserver.integration.ClientAndServer;
17+
import org.mockserver.verify.VerificationTimes;
18+
import org.slf4j.Logger;
19+
import org.springframework.boot.web.server.LocalServerPort;
20+
import org.springframework.http.HttpStatus;
21+
import org.springframework.http.ResponseEntity;
22+
import org.springframework.test.context.TestPropertySource;
23+
24+
import com.ericsson.ei.utils.FunctionalTestBase;
25+
import com.ericsson.ei.utils.HttpRequest;
26+
import com.ericsson.eiffelcommons.subscriptionobject.RestPostSubscriptionObject;
27+
28+
import cucumber.api.java.Before;
29+
import cucumber.api.java.en.Then;
30+
import cucumber.api.java.en.When;
31+
32+
@Ignore
33+
@TestPropertySource(properties = { "spring.data.mongodb.database: EncryptionSteps",
34+
"missedNotificationDataBaseName: EncryptionSteps-missedNotifications",
35+
"rabbitmq.exchange.name: EncryptionSteps-exchange",
36+
"rabbitmq.consumerName: EncryptionSteps-consumer"})
37+
public class EncryptionSteps extends FunctionalTestBase {
38+
39+
private static final Logger LOGGER = getLogger(EncryptionSteps.class);
40+
41+
private static final String EIFFEL_EVENTS_JSON_PATH = "src/functionaltests/resources/eiffel_events_for_test.json";
42+
private static final String SUBSCRIPTION_GET_ENDPOINT = "/subscriptions/<name>";
43+
private static final String SUBSCRIPTION_ROOT_ENDPOINT = "/subscriptions";
44+
private static final String MOCK_ENDPOINT = "/notify-me";
45+
private static final String AUTH_HEADER_NAME = "Authorization";
46+
private static final String AUTH_HEADER_VALUE = "Basic dXNlcm5hbWU6cGFzc3dvcmQ=";
47+
private static final int NOTIFICATION_SLEEP = 5;
48+
49+
private static final String SUBSCRIPTION_NAME = "MySubscription";
50+
private static final String MEDIA_TYPE = "application/x-www-form-urlencoded";
51+
private static final String NOTIFICATION_META = "http://localhost:{port}/notify-me";
52+
private static final String CONDITION_KEY = "jmespath";
53+
private static final String CONDITION_VALUE = "split(identity, '/') | [1] =='com.mycompany.myproduct'";
54+
private static final String USERNAME = "username";
55+
private static final String PASSWORD = "password";
56+
private static final String AUTH_TYPE = "BASIC_AUTH";
57+
58+
@LocalServerPort
59+
private int applicationPort;
60+
61+
private ResponseEntity response;
62+
private String mockServerPort;
63+
private ClientAndServer clientAndServer;
64+
65+
@Before
66+
public void init() throws IOException {
67+
clientAndServer = ClientAndServer.startClientAndServer();
68+
mockServerPort = String.valueOf(clientAndServer.getLocalPort());
69+
setUpMock();
70+
}
71+
72+
@When("^a subscription is created$")
73+
public void subscriptionIsCreated() throws Exception {
74+
LOGGER.debug("Creating a subscription.");
75+
RestPostSubscriptionObject subscription = new RestPostSubscriptionObject(SUBSCRIPTION_NAME);
76+
subscription.setNotificationMeta(NOTIFICATION_META.replace("{port}", mockServerPort));
77+
subscription.setRestPostBodyMediaType(MEDIA_TYPE);
78+
subscription.addNotificationMessageKeyValue("json", "dummy");
79+
JSONObject condition = new JSONObject().put(CONDITION_KEY, CONDITION_VALUE);
80+
subscription.addConditionToRequirement(0, condition);
81+
subscription.setUsername(USERNAME);
82+
subscription.setPassword(PASSWORD);
83+
subscription.setAuthenticationType(AUTH_TYPE);
84+
85+
List<String> subscriptionsToSend = new ArrayList<>();
86+
subscriptionsToSend.add(subscription.toString());
87+
postSubscriptions(subscriptionsToSend.toString());
88+
validateSubscriptionsSuccessfullyAdded();
89+
}
90+
91+
@When("^eiffel events are sent$")
92+
public void eiffelEventsAreSent() throws IOException, InterruptedException {
93+
LOGGER.debug("Sending Eiffel events.");
94+
List<String> eventNamesToSend = getEventNamesToSend();
95+
eventManager.sendEiffelEvents(EIFFEL_EVENTS_JSON_PATH, eventNamesToSend);
96+
List<String> eventsIdList = eventManager.getEventsIdList(EIFFEL_EVENTS_JSON_PATH,
97+
eventNamesToSend);
98+
List<String> missingEventIds = dbManager.verifyEventsInDB(eventsIdList, 0);
99+
String errorMessage = "The following events are missing in mongoDB: "
100+
+ missingEventIds.toString();
101+
assertEquals(errorMessage, 0, missingEventIds.size());
102+
}
103+
104+
@Then("^the password should be encrypted in the database$")
105+
public void passwordShouldBeEncrypted() {
106+
LOGGER.debug("Verifying encoded password in subscription.");
107+
String json = dbManager.getSubscription(SUBSCRIPTION_NAME);
108+
JSONObject subscription = new JSONObject(json);
109+
String password = subscription.getString("password");
110+
assertTrue(EncryptionUtils.isEncrypted(password));
111+
}
112+
113+
@Then("^the subscription should trigger$")
114+
public void subscriptionShouldTrigger() throws InterruptedException {
115+
LOGGER.info("Verifying that subscription was triggered");
116+
TimeUnit.SECONDS.sleep(NOTIFICATION_SLEEP);
117+
clientAndServer.verify(request().withPath(MOCK_ENDPOINT).withBody(""),
118+
VerificationTimes.atLeast(1));
119+
}
120+
121+
@Then("^the notification should be sent with a decrypted password$")
122+
public void notificationShouldBeSentWithDecryptedPassword() {
123+
LOGGER.info("Verifying that notification contains decrypted password");
124+
clientAndServer.verify(
125+
request().withPath(MOCK_ENDPOINT).withHeader(AUTH_HEADER_NAME, AUTH_HEADER_VALUE),
126+
VerificationTimes.atLeast(1));
127+
}
128+
129+
private void postSubscriptions(String jsonDataAsString) throws Exception {
130+
HttpRequest postRequest = new HttpRequest(HttpRequest.HttpMethod.POST);
131+
response = postRequest.setHost(getHostName())
132+
.setPort(applicationPort)
133+
.addHeader("content-type", "application/json")
134+
.addHeader("Accept", "application/json")
135+
.setEndpoint(SUBSCRIPTION_ROOT_ENDPOINT)
136+
.setBody(jsonDataAsString)
137+
.performRequest();
138+
assertEquals("Expected to add subscription to EI", HttpStatus.OK.value(),
139+
response.getStatusCodeValue());
140+
}
141+
142+
private void validateSubscriptionsSuccessfullyAdded()
143+
throws Exception {
144+
String endpoint = SUBSCRIPTION_GET_ENDPOINT.replaceAll("<name>", SUBSCRIPTION_NAME);
145+
HttpRequest getRequest = new HttpRequest(HttpRequest.HttpMethod.GET);
146+
response = getRequest.setHost(getHostName())
147+
.setPort(applicationPort)
148+
.addHeader("content-type", "application/json")
149+
.addHeader("Accept", "application/json")
150+
.setEndpoint(endpoint)
151+
.performRequest();
152+
assertEquals("Subscription successfully added in EI: ", HttpStatus.OK.value(),
153+
response.getStatusCodeValue());
154+
}
155+
156+
private List<String> getEventNamesToSend() {
157+
List<String> eventNames = new ArrayList<>();
158+
eventNames.add("event_EiffelArtifactCreatedEvent_3");
159+
return eventNames;
160+
}
161+
162+
private void setUpMock() {
163+
clientAndServer.when(request().withMethod("POST").withPath(MOCK_ENDPOINT))
164+
.respond(response().withStatusCode(200).withBody(""));
165+
}
166+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.ericsson.ei.encryption;
2+
3+
import org.junit.BeforeClass;
4+
import org.junit.runner.RunWith;
5+
6+
import cucumber.api.CucumberOptions;
7+
import cucumber.api.junit.Cucumber;
8+
9+
@RunWith(Cucumber.class)
10+
@CucumberOptions(features = "src/functionaltests/resources/features/encryption.feature", glue = {
11+
"com.ericsson.ei.encryption" }, plugin = {
12+
"html:target/cucumber-reports/TestEncryptionRunner" })
13+
public class TestEncryptionRunner {
14+
15+
@BeforeClass
16+
public static void configureLdapProperties() {
17+
System.setProperty("jasypt.encryptor.password", "secret");
18+
}
19+
}

0 commit comments

Comments
 (0)