Merge pull request #3612 from hmlnarik/KEYCLOAK-3655-Unexpected-server-error-when-adding-duplicate-auth-flow
KEYCLOAK-3655 Tests for adding duplicate auth flow
This commit is contained in:
commit
287593d75f
5 changed files with 232 additions and 3 deletions
|
@ -19,6 +19,7 @@ package org.keycloak.testsuite.admin.authentication;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.keycloak.events.admin.OperationType;
|
import org.keycloak.events.admin.OperationType;
|
||||||
import org.keycloak.events.admin.ResourceType;
|
import org.keycloak.events.admin.ResourceType;
|
||||||
import org.keycloak.representations.idm.AuthenticationExecutionExportRepresentation;
|
import org.keycloak.representations.idm.AuthenticationExecutionExportRepresentation;
|
||||||
|
@ -31,6 +32,10 @@ import javax.ws.rs.core.Response;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
|
||||||
|
import static org.hamcrest.Matchers.*;
|
||||||
|
import static org.keycloak.testsuite.util.Matchers.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
|
* @author <a href="mailto:mstrukel@redhat.com">Marko Strukelj</a>
|
||||||
|
@ -195,7 +200,9 @@ public class FlowTest extends AbstractAuthenticationTest {
|
||||||
// copy using existing alias as new name
|
// copy using existing alias as new name
|
||||||
Response response = authMgmtResource.copy("browser", params);
|
Response response = authMgmtResource.copy("browser", params);
|
||||||
try {
|
try {
|
||||||
Assert.assertEquals("Copy flow using the new alias of existing flow should fail", 409, response.getStatus());
|
Assert.assertThat("Copy flow using the new alias of existing flow should fail", response, statusCodeIs(Status.CONFLICT));
|
||||||
|
Assert.assertThat("Copy flow using the new alias of existing flow should fail", response, body(containsString("already exists")));
|
||||||
|
Assert.assertThat("Copy flow using the new alias of existing flow should fail", response, body(containsString("flow alias")));
|
||||||
} finally {
|
} finally {
|
||||||
response.close();
|
response.close();
|
||||||
}
|
}
|
||||||
|
@ -204,7 +211,7 @@ public class FlowTest extends AbstractAuthenticationTest {
|
||||||
params.clear();
|
params.clear();
|
||||||
response = authMgmtResource.copy("non-existent", params);
|
response = authMgmtResource.copy("non-existent", params);
|
||||||
try {
|
try {
|
||||||
Assert.assertEquals("Copy non-existing flow", 404, response.getStatus());
|
Assert.assertThat("Copy non-existing flow", response, statusCodeIs(Status.NOT_FOUND));
|
||||||
} finally {
|
} finally {
|
||||||
response.close();
|
response.close();
|
||||||
}
|
}
|
||||||
|
@ -214,7 +221,7 @@ public class FlowTest extends AbstractAuthenticationTest {
|
||||||
response = authMgmtResource.copy("browser", params);
|
response = authMgmtResource.copy("browser", params);
|
||||||
assertAdminEvents.assertEvent(REALM_NAME, OperationType.CREATE, AdminEventPaths.authCopyFlowPath("browser"), params, ResourceType.AUTH_FLOW);
|
assertAdminEvents.assertEvent(REALM_NAME, OperationType.CREATE, AdminEventPaths.authCopyFlowPath("browser"), params, ResourceType.AUTH_FLOW);
|
||||||
try {
|
try {
|
||||||
Assert.assertEquals("Copy flow", 201, response.getStatus());
|
Assert.assertThat("Copy flow", response, statusCodeIs(Status.CREATED));
|
||||||
} finally {
|
} finally {
|
||||||
response.close();
|
response.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2016 Red Hat, Inc. and/or its affiliates
|
||||||
|
* and other contributors as indicated by the @author tags.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.keycloak.testsuite.util;
|
||||||
|
|
||||||
|
import org.keycloak.testsuite.util.matchers.ResponseBodyMatcher;
|
||||||
|
import org.keycloak.testsuite.util.matchers.ResponseHeaderMatcher;
|
||||||
|
import org.keycloak.testsuite.util.matchers.ResponseStatusCodeMatcher;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import org.hamcrest.Matcher;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Additional hamcrest matchers for use in {@link org.junit.Assert#assertThat}.
|
||||||
|
* @author hmlnarik
|
||||||
|
*/
|
||||||
|
public class Matchers {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Matcher on HTTP status code of a {@link Response} instance.
|
||||||
|
* @param matcher
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Matcher<Response> body(Matcher<String> matcher) {
|
||||||
|
return new ResponseBodyMatcher(matcher);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Matcher on HTTP status code of a {@link Response} instance.
|
||||||
|
* @param matcher
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Matcher<Response> statusCode(Matcher<? extends Number> matcher) {
|
||||||
|
return new ResponseStatusCodeMatcher(matcher);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Matches when the HTTP status code of a {@link Response} instance is equal to the given code.
|
||||||
|
* @param expectedStatusCode
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Matcher<Response> statusCodeIs(Response.Status expectedStatusCode) {
|
||||||
|
return new ResponseStatusCodeMatcher(org.hamcrest.Matchers.is(expectedStatusCode.getStatusCode()));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Matches when the HTTP status code of a {@link Response} instance is equal to the given code.
|
||||||
|
* @param expectedStatusCode
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Matcher<Response> statusCodeIs(int expectedStatusCode) {
|
||||||
|
return new ResponseStatusCodeMatcher(org.hamcrest.Matchers.is(expectedStatusCode));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Matches when the HTTP status code of a {@link Response} instance is equal to the given code.
|
||||||
|
* @param expectedStatusCode
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static <T> Matcher<Response> header(Matcher<Map<String, T>> matcher) {
|
||||||
|
return new ResponseHeaderMatcher(matcher);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2016 Red Hat, Inc. and/or its affiliates
|
||||||
|
* and other contributors as indicated by the @author tags.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.keycloak.testsuite.util.matchers;
|
||||||
|
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import org.hamcrest.BaseMatcher;
|
||||||
|
import org.hamcrest.Description;
|
||||||
|
import org.hamcrest.Matcher;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Matcher for matching status code of {@link Response} instance.
|
||||||
|
* @author hmlnarik
|
||||||
|
*/
|
||||||
|
public class ResponseBodyMatcher extends BaseMatcher<Response> {
|
||||||
|
|
||||||
|
private final Matcher<String> matcher;
|
||||||
|
|
||||||
|
public ResponseBodyMatcher(Matcher<String> matcher) {
|
||||||
|
this.matcher = matcher;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matches(Object item) {
|
||||||
|
if (item instanceof Response) {
|
||||||
|
final Response rItem = (Response) item;
|
||||||
|
rItem.bufferEntity();
|
||||||
|
return this.matcher.matches(rItem.readEntity(String.class));
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void describeTo(Description description) {
|
||||||
|
description.appendText("response body matches ").appendDescriptionOf(this.matcher);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2016 Red Hat, Inc. and/or its affiliates
|
||||||
|
* and other contributors as indicated by the @author tags.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.keycloak.testsuite.util.matchers;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import org.hamcrest.BaseMatcher;
|
||||||
|
import org.hamcrest.Description;
|
||||||
|
import org.hamcrest.Matcher;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Matcher for matching status code of {@link Response} instance.
|
||||||
|
* @author hmlnarik
|
||||||
|
*/
|
||||||
|
public class ResponseHeaderMatcher<T> extends BaseMatcher<Response> {
|
||||||
|
|
||||||
|
private final Matcher<Map<String, T>> matcher;
|
||||||
|
|
||||||
|
public ResponseHeaderMatcher(Matcher<Map<String, T>> matcher) {
|
||||||
|
this.matcher = matcher;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matches(Object item) {
|
||||||
|
return (item instanceof Response) && this.matcher.matches(((Response) item).getHeaders());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void describeTo(Description description) {
|
||||||
|
description.appendText("response headers match ").appendDescriptionOf(this.matcher);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2016 Red Hat, Inc. and/or its affiliates
|
||||||
|
* and other contributors as indicated by the @author tags.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.keycloak.testsuite.util.matchers;
|
||||||
|
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import org.hamcrest.BaseMatcher;
|
||||||
|
import org.hamcrest.Description;
|
||||||
|
import org.hamcrest.Matcher;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Matcher for matching status code of {@link Response} instance.
|
||||||
|
* @author hmlnarik
|
||||||
|
*/
|
||||||
|
public class ResponseStatusCodeMatcher extends BaseMatcher<Response> {
|
||||||
|
|
||||||
|
private final Matcher<? extends Number> matcher;
|
||||||
|
|
||||||
|
public ResponseStatusCodeMatcher(Matcher<? extends Number> matcher) {
|
||||||
|
this.matcher = matcher;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean matches(Object item) {
|
||||||
|
return (item instanceof Response) && this.matcher.matches(((Response) item).getStatus());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void describeTo(Description description) {
|
||||||
|
description.appendText("response status code matches ").appendDescriptionOf(this.matcher);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue