introduce Context service
This commit is contained in:
@@ -1,26 +0,0 @@
|
||||
package net.hostsharing.hsadminng;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
@DataJpaTest
|
||||
class RbacIntegrationTests {
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager em;
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
void currentUser() {
|
||||
em.createNativeQuery("SET LOCAL hsadminng.currentUser = 'mike@hostsharing.net';").executeUpdate();
|
||||
em.createNativeQuery("SET LOCAL hsadminng.assumedRoles = '';").executeUpdate();
|
||||
|
||||
final var result = em.createNativeQuery("select currentUser()").getSingleResult();
|
||||
Assertions.assertThat(result).isEqualTo("mike@hostsharing.net");
|
||||
}
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
package net.hostsharing.hsadminng.context;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@DataJpaTest
|
||||
@ComponentScan(basePackageClasses = Context.class)
|
||||
class ContextIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
private Context context;
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
void setCurrentUser() {
|
||||
context.setCurrentUser("mike@hostsharing.net");
|
||||
|
||||
final var currentUser = context.getCurrentUser();
|
||||
assertThat(currentUser).isEqualTo("mike@hostsharing.net");
|
||||
|
||||
final var assumedRoles = context.getAssumedRoles();
|
||||
assertThat(assumedRoles).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
void assumeRoles() {
|
||||
context.setCurrentUser("mike@hostsharing.net");
|
||||
context.assumeRoles("customer#aaa.owner;customer#aab.owner");
|
||||
|
||||
final var currentUser = context.getCurrentUser();
|
||||
assertThat(currentUser).isEqualTo("mike@hostsharing.net");
|
||||
|
||||
final var assumedRoles = context.getAssumedRoles();
|
||||
assertThat(assumedRoles).containsExactlyInAnyOrder("customer#aaa.owner", "customer#aab.owner");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user