-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding IT for communication between gateway and console with rabbitmq
- Loading branch information
1 parent
c36dd87
commit 068bab3
Showing
5 changed files
with
490 additions
and
0 deletions.
There are no files selected for viewing
147 changes: 147 additions & 0 deletions
147
gateway/src/test/java/org/georchestra/gateway/rabbitmq/SendMessageRabbitmqIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
package org.georchestra.gateway.rabbitmq; | ||
|
||
import lombok.NonNull; | ||
import org.geonetwork.testcontainers.postgres.GeorchestraDatabaseContainer; | ||
import org.georchestra.ds.orgs.OrgsDao; | ||
import org.georchestra.ds.users.AccountDao; | ||
import org.georchestra.gateway.accounts.admin.AccountCreated; | ||
import org.georchestra.gateway.accounts.admin.CreateAccountUserCustomizer; | ||
import org.georchestra.gateway.accounts.events.rabbitmq.RabbitmqAccountCreatedEventSender; | ||
import org.georchestra.gateway.app.GeorchestraGatewayApplication; | ||
import org.georchestra.security.api.UsersApi; | ||
import org.georchestra.security.model.GeorchestraUser; | ||
import org.georchestra.testcontainers.console.GeorchestraConsoleContainer; | ||
import org.georchestra.testcontainers.ldap.GeorchestraLdapContainer; | ||
import org.georchestra.testcontainers.rabbitmq.RabbitmqContainer; | ||
import org.georchestra.testcontainers.smtp.SmtpContainer; | ||
import org.hamcrest.Matchers; | ||
import org.junit.ClassRule; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.system.CapturedOutput; | ||
import org.springframework.boot.test.system.OutputCaptureExtension; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.ApplicationEventPublisher; | ||
import org.springframework.ldap.NameNotFoundException; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.TestPropertySource; | ||
import org.springframework.test.web.reactive.server.WebTestClient; | ||
import org.testcontainers.Testcontainers; | ||
import org.testcontainers.utility.MountableFile; | ||
|
||
import java.net.InterfaceAddress; | ||
import java.net.NetworkInterface; | ||
import java.net.SocketException; | ||
import java.util.*; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.testcontainers.shaded.org.awaitility.Awaitility.await; | ||
|
||
/** | ||
* Integration tests for {@link RabbitmqAccountCreatedEventSender}. | ||
*/ | ||
@SpringBootTest(classes = GeorchestraGatewayApplication.class) | ||
@TestPropertySource(properties = { // | ||
"georchestra.datadir=${user.dir}/src/test/resources/data_directory" }) | ||
@ActiveProfiles("rabbitmq") | ||
@ExtendWith(OutputCaptureExtension.class) | ||
public class SendMessageRabbitmqIT { | ||
|
||
private @Autowired ApplicationEventPublisher eventPublisher; | ||
private @Autowired ApplicationContext context; | ||
private @Autowired RabbitmqAccountCreatedEventSender sender; | ||
private @Autowired AccountDao accountDao; | ||
private @Autowired OrgsDao orgsDao; | ||
|
||
public static GeorchestraLdapContainer ldap = new GeorchestraLdapContainer(); | ||
public static GeorchestraDatabaseContainer db = new GeorchestraDatabaseContainer(); | ||
public static SmtpContainer smtp = new SmtpContainer(); | ||
public static GeorchestraConsoleContainer console; | ||
public static RabbitmqContainer rabbitmq = new RabbitmqContainer(); | ||
|
||
public static @BeforeAll void startUpContainers() { | ||
|
||
db.start(); | ||
ldap.start(); | ||
smtp.start(); | ||
rabbitmq.withLogToStdOut().start(); | ||
|
||
Testcontainers.exposeHostPorts(ldap.getMappedLdapPort(), db.getMappedDatabasePort()); | ||
|
||
System.setProperty("georchestra.gateway.security.events.rabbitmq.host", getLocalIpAddress()); | ||
System.setProperty("georchestra.gateway.security.events.rabbitmq.port", | ||
String.valueOf(rabbitmq.getMappedRabbitmqPort())); | ||
|
||
console = new GeorchestraConsoleContainer()// | ||
.withCopyFileToContainer(MountableFile.forClasspathResource("data_directory"), "/etc/georchestra")// | ||
.withEnv("pgsqlHost", "host.testcontainers.internal")// | ||
.withEnv("pgsqlPort", String.valueOf(db.getMappedDatabasePort()))// | ||
.withEnv("ldapHost", "host.testcontainers.internal")// | ||
.withEnv("ldapPort", String.valueOf(ldap.getMappedLdapPort()))// | ||
.withEnv("rabbitmqHost", getLocalIpAddress())// | ||
.withEnv("rabbitmqPort", String.valueOf(rabbitmq.getMappedRabbitmqPort()))// | ||
.withEnv("smtpHost", getLocalIpAddress())// | ||
.withEnv("smtpPort", String.valueOf(smtp.getMappedSmtpPort()))// | ||
.withLogToStdOut(); | ||
|
||
console.start(); | ||
System.setProperty("georchestra.console.url", | ||
String.format("http://localhost:%d", console.getMappedConsolePort())); | ||
} | ||
|
||
public static @AfterAll void shutDownContainers() { | ||
console.stop(); | ||
ldap.stop(); | ||
db.stop(); | ||
smtp.stop(); | ||
rabbitmq.stop(); | ||
} | ||
|
||
public @Test void testReceivingMessageFromConsole(CapturedOutput output) throws Exception { | ||
assertNotNull(sender); | ||
GeorchestraUser user = new GeorchestraUser(); | ||
user.setId(UUID.randomUUID().toString()); | ||
user.setLastUpdated("anystringwoulddo"); | ||
user.setUsername("testadmin"); | ||
user.setEmail("testadmin@georchestra.org"); | ||
user.setFirstName("John"); | ||
user.setLastName("Doe"); | ||
user.setRoles(Arrays.asList("ADMINISTRATOR", "GN_ADMIN")); | ||
user.setTelephoneNumber("341444111"); | ||
user.setTitle("developer"); | ||
user.setNotes("user notes"); | ||
user.setPostalAddress("123 java street"); | ||
user.setOrganization("PSC"); | ||
user.setOAuth2ProviderId("testIDP"); | ||
eventPublisher.publishEvent(new AccountCreated(user)); | ||
await().atMost(30, TimeUnit.SECONDS).until(() -> { | ||
return output.getOut().contains( | ||
"new OAuth2 account creation notification for testadmin@georchestra.org has been received by console"); | ||
}); | ||
} | ||
|
||
private static String getLocalIpAddress() { | ||
try { | ||
Enumeration<NetworkInterface> networkInterfaceEnumeration = NetworkInterface.getNetworkInterfaces(); | ||
while (networkInterfaceEnumeration.hasMoreElements()) { | ||
for (InterfaceAddress interfaceAddress : networkInterfaceEnumeration.nextElement() | ||
.getInterfaceAddresses()) | ||
if (interfaceAddress.getAddress().isSiteLocalAddress()) | ||
return interfaceAddress.getAddress().getHostAddress(); | ||
} | ||
} catch (SocketException e) { | ||
e.printStackTrace(); | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
georchestra: | ||
gateway: | ||
default-headers: | ||
# Default security headers to append to proxied requests | ||
proxy: true | ||
username: true | ||
roles: true | ||
org: true | ||
orgname: true | ||
global-access-rules: | ||
- intercept-url: | ||
- "/**" | ||
- "/proxy/?url=*" | ||
anonymous: true | ||
security: | ||
createNonExistingUsersInLDAP: true | ||
oauth2.enabled: false | ||
header-authentication: | ||
enabled: true | ||
ldap: | ||
default: | ||
enabled: true | ||
extended: true | ||
url: ldap://${ldapHost}:${ldapPort}/ | ||
baseDn: dc=georchestra,dc=org | ||
adminDn: cn=admin,dc=georchestra,dc=org | ||
adminPassword: secret | ||
users: | ||
rdn: ou=users | ||
searchFilter: (uid={0}) | ||
pendingUsersSearchBaseDN: ou=pendingusers | ||
protectedUsers: geoserver_privileged_user | ||
roles: | ||
rdn: ou=roles | ||
searchFilter: (member={0}) | ||
protectedRoles: ADMINISTRATOR, EXTRACTORAPP, GN_.*, ORGADMIN, REFERENT, USER, SUPERUSER | ||
orgs: | ||
rdn: ou=orgs | ||
orgTypes: Association,Company,NGO,Individual,Other | ||
pendingOrgSearchBaseDN: ou=pendingorgs | ||
events: | ||
rabbitmq: | ||
# Note usually enableRabbitmqEvents, rabbitmqHost, etc. come from georchestra's default.properties | ||
enabled: true | ||
host: localhost | ||
port: 5672 | ||
user: georchestra | ||
password: georchestra | ||
spring: | ||
main: | ||
web-application-type: reactive | ||
banner-mode: off | ||
application.name: gateway-service | ||
cloud: | ||
gateway: | ||
enabled: true | ||
default-filters: | ||
- SecureHeaders | ||
- TokenRelay | ||
- RemoveSecurityHeaders | ||
# AddSecHeaders appends sec-* headers to proxied requests based on the | ||
# georchestra.gateway.default-headers and georchestra.gateway.servies.<service>.headers config properties | ||
- AddSecHeaders | ||
httpclient.wiretap: true | ||
httpserver.wiretap: false |
Oops, something went wrong.