Search in sources :

Example 1 with ClassPropertiesLoader

use of io.cryostat.util.resource.ClassPropertiesLoader in project cryostat by cryostatio.

the class OpenShiftAuthManagerTest method testPropertiesResourceMapProcessing.

@ParameterizedTest
@MethodSource("getResourceMaps")
void testPropertiesResourceMapProcessing(Map<String, Object> map) throws IOException {
    ClassPropertiesLoader loader = Mockito.mock(ClassPropertiesLoader.class);
    Map<String, String> resourcesMap = new HashMap<>();
    map.entrySet().stream().filter(e -> !e.getKey().equals("expected")).forEach(e -> resourcesMap.put((String) e.getKey(), (String) e.getValue()));
    Map<ResourceType, Set<GroupResource>> expected = (Map<ResourceType, Set<GroupResource>>) map.get("expected");
    Mockito.when(loader.loadAsMap(Mockito.any())).thenReturn(resourcesMap);
    Map<ResourceType, Set<GroupResource>> result = OpenShiftAuthManager.processResourceMapping(loader, logger);
    MatcherAssert.assertThat(result, Matchers.equalTo(expected));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) BeforeEach(org.junit.jupiter.api.BeforeEach) OpenShiftMockServerExtension(io.fabric8.openshift.client.server.mock.OpenShiftMockServerExtension) URL(java.net.URL) MultiMap(io.vertx.core.MultiMap) Scheduler(com.github.benmanes.caffeine.cache.Scheduler) GroupResource(io.cryostat.net.openshift.OpenShiftAuthManager.GroupResource) UserInfo(io.cryostat.net.UserInfo) Resource(io.fabric8.kubernetes.client.dsl.Resource) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) MissingEnvironmentVariableException(io.cryostat.net.MissingEnvironmentVariableException) BeforeAll(org.junit.jupiter.api.BeforeAll) Gson(com.google.gson.Gson) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) AuthenticationScheme(io.cryostat.net.AuthenticationScheme) ResponseBody(okhttp3.ResponseBody) MethodSource(org.junit.jupiter.params.provider.MethodSource) NullAndEmptySource(org.junit.jupiter.params.provider.NullAndEmptySource) Request(okhttp3.Request) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) RecordedRequest(okhttp3.mockwebserver.RecordedRequest) ResourceType(io.cryostat.net.security.ResourceType) Set(java.util.Set) TokenReview(io.fabric8.kubernetes.api.model.authentication.TokenReview) OAuthAccessToken(io.fabric8.openshift.api.model.OAuthAccessToken) HttpHeaders(io.vertx.core.http.HttpHeaders) OpenShiftMockServer(io.fabric8.openshift.client.server.mock.OpenShiftMockServer) Test(org.junit.jupiter.api.Test) Config(io.fabric8.kubernetes.client.Config) Stream(java.util.stream.Stream) MatcherAssert(org.hamcrest.MatcherAssert) TokenNotFoundException(io.cryostat.net.TokenNotFoundException) HttpUrl(okhttp3.HttpUrl) MainModule(io.cryostat.MainModule) OAuthAccessTokenList(io.fabric8.openshift.api.model.OAuthAccessTokenList) ExceptionUtils(org.apache.commons.lang3.exception.ExceptionUtils) CsvSource(org.junit.jupiter.params.provider.CsvSource) SelfSubjectAccessReviewBuilder(io.fabric8.kubernetes.api.model.authorization.v1.SelfSubjectAccessReviewBuilder) SelfSubjectAccessReview(io.fabric8.kubernetes.api.model.authorization.v1.SelfSubjectAccessReview) Mock(org.mockito.Mock) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) EnumSource(org.junit.jupiter.params.provider.EnumSource) ResourceVerb(io.cryostat.net.security.ResourceVerb) Function(java.util.function.Function) HashSet(java.util.HashSet) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArgumentCaptor(org.mockito.ArgumentCaptor) Logger(io.cryostat.core.log.Logger) Response(okhttp3.Response) Call(okhttp3.Call) Callback(okhttp3.Callback) Environment(io.cryostat.core.sys.Environment) ValueSource(org.junit.jupiter.params.provider.ValueSource) Matchers(org.hamcrest.Matchers) IOException(java.io.IOException) OpenShiftClient(io.fabric8.openshift.client.OpenShiftClient) PermissionDeniedException(io.cryostat.net.PermissionDeniedException) TokenReviewBuilder(io.fabric8.kubernetes.api.model.authentication.TokenReviewBuilder) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Mockito(org.mockito.Mockito) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) NonNamespaceOperation(io.fabric8.kubernetes.client.dsl.NonNamespaceOperation) OkHttpClient(okhttp3.OkHttpClient) Assertions(org.junit.jupiter.api.Assertions) EnableOpenShiftMockClient(io.fabric8.openshift.client.server.mock.EnableOpenShiftMockClient) NullSource(org.junit.jupiter.params.provider.NullSource) ClassPropertiesLoader(io.cryostat.util.resource.ClassPropertiesLoader) ResourceAction(io.cryostat.net.security.ResourceAction) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ResourceType(io.cryostat.net.security.ResourceType) MultiMap(io.vertx.core.MultiMap) Map(java.util.Map) HashMap(java.util.HashMap) GroupResource(io.cryostat.net.openshift.OpenShiftAuthManager.GroupResource) ClassPropertiesLoader(io.cryostat.util.resource.ClassPropertiesLoader) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

Scheduler (com.github.benmanes.caffeine.cache.Scheduler)1 Gson (com.google.gson.Gson)1 MainModule (io.cryostat.MainModule)1 Logger (io.cryostat.core.log.Logger)1 Environment (io.cryostat.core.sys.Environment)1 AuthenticationScheme (io.cryostat.net.AuthenticationScheme)1 MissingEnvironmentVariableException (io.cryostat.net.MissingEnvironmentVariableException)1 PermissionDeniedException (io.cryostat.net.PermissionDeniedException)1 TokenNotFoundException (io.cryostat.net.TokenNotFoundException)1 UserInfo (io.cryostat.net.UserInfo)1 GroupResource (io.cryostat.net.openshift.OpenShiftAuthManager.GroupResource)1 ResourceAction (io.cryostat.net.security.ResourceAction)1 ResourceType (io.cryostat.net.security.ResourceType)1 ResourceVerb (io.cryostat.net.security.ResourceVerb)1 ClassPropertiesLoader (io.cryostat.util.resource.ClassPropertiesLoader)1 TokenReview (io.fabric8.kubernetes.api.model.authentication.TokenReview)1 TokenReviewBuilder (io.fabric8.kubernetes.api.model.authentication.TokenReviewBuilder)1 SelfSubjectAccessReview (io.fabric8.kubernetes.api.model.authorization.v1.SelfSubjectAccessReview)1 SelfSubjectAccessReviewBuilder (io.fabric8.kubernetes.api.model.authorization.v1.SelfSubjectAccessReviewBuilder)1 Config (io.fabric8.kubernetes.client.Config)1