Search in sources :

Example 1 with GroupResource

use of io.cryostat.net.openshift.OpenShiftAuthManager.GroupResource in project cryostat by cryostatio.

the class OpenShiftAuthManagerTest method shouldParseResourceWithGroup.

@Test
void shouldParseResourceWithGroup() {
    GroupResource gr = OpenShiftAuthManager.GroupResource.fromString("deployments.apps");
    MatcherAssert.assertThat(gr.getGroup(), Matchers.equalTo("apps"));
    MatcherAssert.assertThat(gr.getResource(), Matchers.equalTo("deployments"));
    MatcherAssert.assertThat(gr.getSubResource(), Matchers.emptyString());
}
Also used : GroupResource(io.cryostat.net.openshift.OpenShiftAuthManager.GroupResource) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with GroupResource

use of io.cryostat.net.openshift.OpenShiftAuthManager.GroupResource in project cryostat by cryostatio.

the class OpenShiftAuthManagerTest method shouldParseBareResource.

// the below parsing tests should be in a @Nested class, but this doesn't play nicely with the
// OpenShiftMockServerExtension and results in a test NPE
@Test
void shouldParseBareResource() {
    GroupResource gr = OpenShiftAuthManager.GroupResource.fromString("apps");
    MatcherAssert.assertThat(gr.getGroup(), Matchers.emptyString());
    MatcherAssert.assertThat(gr.getResource(), Matchers.equalTo("apps"));
    MatcherAssert.assertThat(gr.getSubResource(), Matchers.emptyString());
}
Also used : GroupResource(io.cryostat.net.openshift.OpenShiftAuthManager.GroupResource) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with GroupResource

use of io.cryostat.net.openshift.OpenShiftAuthManager.GroupResource in project cryostat by cryostatio.

the class OpenShiftAuthManagerTest method shouldParseResourceWithSub.

@Test
void shouldParseResourceWithSub() {
    GroupResource gr = OpenShiftAuthManager.GroupResource.fromString("apps/scale");
    MatcherAssert.assertThat(gr.getGroup(), Matchers.emptyString());
    MatcherAssert.assertThat(gr.getResource(), Matchers.equalTo("apps"));
    MatcherAssert.assertThat(gr.getSubResource(), Matchers.equalTo("scale"));
}
Also used : GroupResource(io.cryostat.net.openshift.OpenShiftAuthManager.GroupResource) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with GroupResource

use of io.cryostat.net.openshift.OpenShiftAuthManager.GroupResource 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)

Example 5 with GroupResource

use of io.cryostat.net.openshift.OpenShiftAuthManager.GroupResource in project cryostat by cryostatio.

the class OpenShiftAuthManagerTest method shouldParseResourceWithGroupAndSub.

@Test
void shouldParseResourceWithGroupAndSub() {
    GroupResource gr = OpenShiftAuthManager.GroupResource.fromString("deployments.apps/scale");
    MatcherAssert.assertThat(gr.getGroup(), Matchers.equalTo("apps"));
    MatcherAssert.assertThat(gr.getResource(), Matchers.equalTo("deployments"));
    MatcherAssert.assertThat(gr.getSubResource(), Matchers.equalTo("scale"));
}
Also used : GroupResource(io.cryostat.net.openshift.OpenShiftAuthManager.GroupResource) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

GroupResource (io.cryostat.net.openshift.OpenShiftAuthManager.GroupResource)5 Test (org.junit.jupiter.api.Test)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 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 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