-
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.
fix rabbitmq event sending process after code refactor
- Loading branch information
1 parent
9b3256a
commit 5f6b5d5
Showing
9 changed files
with
413 additions
and
7 deletions.
There are no files selected for viewing
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
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
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
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
124 changes: 124 additions & 0 deletions
124
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,124 @@ | ||
package org.georchestra.gateway.rabbitmq; | ||
|
||
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.events.rabbitmq.RabbitmqAccountCreatedEventSender; | ||
import org.georchestra.gateway.app.GeorchestraGatewayApplication; | ||
import org.georchestra.security.model.GeorchestraUser; | ||
import org.georchestra.testcontainers.console.GeorchestraConsoleContainer; | ||
import org.georchestra.testcontainers.ldap.GeorchestraLdapContainer; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
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.test.context.ActiveProfiles; | ||
import org.springframework.test.context.TestPropertySource; | ||
import org.testcontainers.Testcontainers; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.RabbitMQContainer; | ||
import org.testcontainers.utility.DockerImageName; | ||
import org.testcontainers.utility.MountableFile; | ||
|
||
import java.util.*; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.testcontainers.shaded.org.awaitility.Awaitility.await; | ||
|
||
/** | ||
* Integration tests for {@link RabbitmqAccountCreatedEventSender}. | ||
*/ | ||
@SpringBootTest(classes = GeorchestraGatewayApplication.class) | ||
@ActiveProfiles("rabbitmq") | ||
@ExtendWith(OutputCaptureExtension.class) | ||
@TestPropertySource(properties = { "enableRabbitmqEvents=true", // | ||
"georchestra.datadir=src/test/resources/test-datadir"// | ||
}) | ||
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 int rabbitmqPort = 5672; | ||
public static int smtpPort = 25; | ||
|
||
public static GeorchestraLdapContainer ldap = new GeorchestraLdapContainer(); | ||
public static GeorchestraDatabaseContainer db = new GeorchestraDatabaseContainer(); | ||
public static RabbitMQContainer rabbitmq = new RabbitMQContainer(DockerImageName.parse("rabbitmq:3.12")) | ||
.withExposedPorts(rabbitmqPort); | ||
public static GenericContainer<?> smtp = new GenericContainer<>("camptocamp/smtp-sink:latest") | ||
.withExposedPorts(smtpPort); | ||
public static GeorchestraConsoleContainer console; | ||
|
||
public static @BeforeAll void startUpContainers() { | ||
db.start(); | ||
ldap.start(); | ||
smtp.start(); | ||
rabbitmq.start(); | ||
|
||
Testcontainers.exposeHostPorts(ldap.getMappedLdapPort(), db.getMappedDatabasePort(), | ||
rabbitmq.getMappedPort(rabbitmqPort), smtp.getMappedPort(smtpPort)); | ||
System.setProperty("georchestra.gateway.security.events.rabbitmq.host", "localhost"); | ||
System.setProperty("georchestra.gateway.security.events.rabbitmq.port", | ||
String.valueOf(rabbitmq.getMappedPort(rabbitmqPort))); | ||
|
||
console = new GeorchestraConsoleContainer()// | ||
.withCopyFileToContainer(MountableFile.forClasspathResource("test-datadir"), "/etc/georchestra")// | ||
.withEnv("enableRabbitmqEvents", "true").withEnv("pgsqlHost", "host.testcontainers.internal")// | ||
.withEnv("pgsqlPort", String.valueOf(db.getMappedDatabasePort()))// | ||
.withEnv("ldapHost", "host.testcontainers.internal")// | ||
.withEnv("ldapPort", String.valueOf(ldap.getMappedLdapPort()))// | ||
.withEnv("rabbitmqHost", "host.testcontainers.internal")// | ||
.withEnv("rabbitmqPort", String.valueOf(rabbitmq.getMappedPort(rabbitmqPort)))// | ||
.withEnv("rabbitmqUser", "guest")// | ||
.withEnv("rabbitmqPassword", "guest")// | ||
.withEnv("smtpHost", "host.testcontainers.internal")// | ||
.withEnv("smtpPort", String.valueOf(smtp.getMappedPort(smtpPort)))// | ||
.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(); | ||
} | ||
|
||
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("[email protected]"); | ||
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.setOAuth2Provider("testProvider"); | ||
user.setOAuth2Uid("123"); | ||
eventPublisher.publishEvent(new AccountCreated(user)); | ||
await().atMost(30, TimeUnit.SECONDS).until(() -> { | ||
return output.getOut().contains( | ||
"new OAuth2 account creation notification for [email protected] has been received by console"); | ||
}); | ||
} | ||
} |
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: ${rabbitmqHost} | ||
port: ${rabbitmqPort} | ||
user: guest | ||
password: guest | ||
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.