Commit 752c280e authored by Rustam Lotsmanenko (EPAM)'s avatar Rustam Lotsmanenko (EPAM)
Browse files

update test cases for not authorized requests(for istio)

parent 81bc1622
Pipeline #112556 passed with stages
in 24 minutes and 57 seconds
......@@ -23,14 +23,18 @@ import com.sun.jersey.api.client.ClientResponse;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.opengroup.osdu.partition.api.util.AnthosAuthorizationTestUtil;
import org.opengroup.osdu.partition.util.AnthosTestUtils;
public class TestCreatePartition extends CreatePartitionTest {
private AnthosAuthorizationTestUtil authorizationTestUtil;
@Override
@Before
public void setup() {
this.testUtils = new AnthosTestUtils();
this.authorizationTestUtil = new AnthosAuthorizationTestUtil(this.descriptor, this.testUtils);
}
@Override
......@@ -38,6 +42,7 @@ public class TestCreatePartition extends CreatePartitionTest {
public void tearDown() throws Exception {
deleteResource();
this.testUtils = null;
this.authorizationTestUtil = null;
}
@Override
......@@ -49,4 +54,19 @@ public class TestCreatePartition extends CreatePartitionTest {
testUtils.getAccessToken());
assertEquals(400, response.getStatus());
}
@Override
public void should_return401_when_noAccessToken() throws Exception {
authorizationTestUtil.should_return401or403_when_noAccessToken(getId());
}
@Override
public void should_return401_when_accessingWithCredentialsWithoutPermission() throws Exception {
authorizationTestUtil.should_return401or403_when_accessingWithCredentialsWithoutPermission(getId());
}
@Override
public void should_return401_when_makingHttpRequestWithoutToken() throws Exception {
authorizationTestUtil.should_return401or403_when_makingHttpRequestWithoutToken(getId());
}
}
......@@ -19,14 +19,18 @@ package org.opengroup.osdu.partition.api;
import org.junit.After;
import org.junit.Before;
import org.opengroup.osdu.partition.api.util.AnthosAuthorizationTestUtil;
import org.opengroup.osdu.partition.util.AnthosTestUtils;
public class TestDeletePartition extends DeletePartitionTest {
private AnthosAuthorizationTestUtil authorizationTestUtil;
@Override
@Before
public void setup() {
this.testUtils = new AnthosTestUtils();
this.authorizationTestUtil = new AnthosAuthorizationTestUtil(this.descriptor, this.testUtils);
}
@Override
......@@ -34,5 +38,21 @@ public class TestDeletePartition extends DeletePartitionTest {
public void tearDown() throws Exception {
deleteResource();
this.testUtils = null;
this.authorizationTestUtil = null;
}
@Override
public void should_return401_when_noAccessToken() throws Exception {
authorizationTestUtil.should_return401or403_when_noAccessToken(getId());
}
@Override
public void should_return401_when_accessingWithCredentialsWithoutPermission() throws Exception {
authorizationTestUtil.should_return401or403_when_accessingWithCredentialsWithoutPermission(getId());
}
@Override
public void should_return401_when_makingHttpRequestWithoutToken() throws Exception {
authorizationTestUtil.should_return401or403_when_makingHttpRequestWithoutToken(getId());
}
}
......@@ -21,14 +21,18 @@ import com.sun.jersey.api.client.ClientResponse;
import org.junit.After;
import org.junit.Before;
import org.opengroup.osdu.partition.api.descriptor.DeletePartitionDescriptor;
import org.opengroup.osdu.partition.api.util.AnthosAuthorizationTestUtil;
import org.opengroup.osdu.partition.util.AnthosTestUtils;
public class TestGetPartitionById extends GetPartitionByIdApitTest {
private AnthosAuthorizationTestUtil authorizationTestUtil;
@Override
@Before
public void setup() {
this.testUtils = new AnthosTestUtils();
this.authorizationTestUtil = new AnthosAuthorizationTestUtil(this.descriptor, this.testUtils);
}
@Override
......@@ -36,6 +40,7 @@ public class TestGetPartitionById extends GetPartitionByIdApitTest {
public void tearDown() throws Exception {
deleteResource();
this.testUtils = null;
this.authorizationTestUtil = null;
}
@Override
......@@ -44,4 +49,19 @@ public class TestGetPartitionById extends GetPartitionByIdApitTest {
deletePartitionDes.setPartitionId(getId());
ClientResponse response = deletePartitionDes.run(getId(), this.testUtils.getAccessToken());
}
@Override
public void should_return401_when_noAccessToken() throws Exception {
authorizationTestUtil.should_return401or403_when_noAccessToken(getId());
}
@Override
public void should_return401_when_accessingWithCredentialsWithoutPermission() throws Exception {
authorizationTestUtil.should_return401or403_when_accessingWithCredentialsWithoutPermission(getId());
}
@Override
public void should_return401_when_makingHttpRequestWithoutToken() throws Exception {
authorizationTestUtil.should_return401or403_when_makingHttpRequestWithoutToken(getId());
}
}
......@@ -21,14 +21,18 @@ import com.sun.jersey.api.client.ClientResponse;
import org.junit.After;
import org.junit.Before;
import org.opengroup.osdu.partition.api.descriptor.DeletePartitionDescriptor;
import org.opengroup.osdu.partition.api.util.AnthosAuthorizationTestUtil;
import org.opengroup.osdu.partition.util.AnthosTestUtils;
public class TestListPartitions extends ListPartitionsApitTest {
private AnthosAuthorizationTestUtil authorizationTestUtil;
@Override
@Before
public void setup() {
this.testUtils = new AnthosTestUtils();
this.authorizationTestUtil = new AnthosAuthorizationTestUtil(this.descriptor, this.testUtils);
}
@Override
......@@ -36,6 +40,7 @@ public class TestListPartitions extends ListPartitionsApitTest {
public void tearDown() throws Exception {
deleteResource();
this.testUtils = null;
this.authorizationTestUtil = null;
}
@Override
......@@ -44,4 +49,19 @@ public class TestListPartitions extends ListPartitionsApitTest {
deletePartitionDes.setPartitionId(getId());
ClientResponse response = deletePartitionDes.run(getId(), this.testUtils.getAccessToken());
}
@Override
public void should_return401_when_noAccessToken() throws Exception {
authorizationTestUtil.should_return401or403_when_noAccessToken(getId());
}
@Override
public void should_return401_when_accessingWithCredentialsWithoutPermission() throws Exception {
authorizationTestUtil.should_return401or403_when_accessingWithCredentialsWithoutPermission(getId());
}
@Override
public void should_return401_when_makingHttpRequestWithoutToken() throws Exception {
authorizationTestUtil.should_return401or403_when_makingHttpRequestWithoutToken(getId());
}
}
......@@ -17,18 +17,24 @@
package org.opengroup.osdu.partition.api;
import static org.junit.Assert.assertEquals;
import com.sun.jersey.api.client.ClientResponse;
import org.junit.After;
import org.junit.Before;
import org.opengroup.osdu.partition.api.descriptor.DeletePartitionDescriptor;
import org.opengroup.osdu.partition.api.util.AnthosAuthorizationTestUtil;
import org.opengroup.osdu.partition.util.AnthosTestUtils;
public class TestUpdatePartition extends UpdatePartitionTest {
private AnthosAuthorizationTestUtil authorizationTestUtil;
@Override
@Before
public void setup() {
this.testUtils = new AnthosTestUtils();
this.authorizationTestUtil = new AnthosAuthorizationTestUtil(this.descriptor, this.testUtils);
}
@Override
......@@ -36,6 +42,7 @@ public class TestUpdatePartition extends UpdatePartitionTest {
public void tearDown() throws Exception {
deleteResource();
this.testUtils = null;
this.authorizationTestUtil = null;
}
@Override
......@@ -44,4 +51,19 @@ public class TestUpdatePartition extends UpdatePartitionTest {
deletePartitionDes.setPartitionId(getId());
ClientResponse response = deletePartitionDes.run(getId(), this.testUtils.getAccessToken());
}
@Override
public void should_return401_when_noAccessToken() throws Exception {
authorizationTestUtil.should_return401or403_when_noAccessToken(getId());
}
@Override
public void should_return401_when_accessingWithCredentialsWithoutPermission() throws Exception {
authorizationTestUtil.should_return401or403_when_accessingWithCredentialsWithoutPermission(getId());
}
@Override
public void should_return401_when_makingHttpRequestWithoutToken() throws Exception {
authorizationTestUtil.should_return401or403_when_makingHttpRequestWithoutToken(getId());
}
}
/*
* Copyright 2020-2022 Google LLC
* Copyright 2020-2022 EPAM Systems, Inc
*
* 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
*
* https://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.opengroup.osdu.partition.api.util;
import static org.hamcrest.core.AnyOf.anyOf;
import static org.junit.Assert.assertThat;
import com.sun.jersey.api.client.ClientResponse;
import org.hamcrest.core.Is;
import org.opengroup.osdu.partition.util.RestDescriptor;
import org.opengroup.osdu.partition.util.TestUtils;
public class AnthosAuthorizationTestUtil {
private RestDescriptor descriptor;
private TestUtils testUtils;
public AnthosAuthorizationTestUtil(RestDescriptor descriptor, TestUtils testUtils) {
this.descriptor = descriptor;
this.testUtils = testUtils;
}
public void should_return401or403_when_noAccessToken(String partitionId) throws Exception {
ClientResponse response = descriptor.runOnCustomerTenant(partitionId, testUtils.getNoAccessToken());
assertThat(error(response.getEntity(String.class)), response.getStatus(), anyOf(Is.is(401), Is.is(403)));
}
public void should_return401or403_when_accessingWithCredentialsWithoutPermission(String partitionId) throws Exception {
ClientResponse response = descriptor.run(partitionId, testUtils.getNoAccessToken());
assertThat(error(response.getEntity(String.class)), response.getStatus(), anyOf(Is.is(401), Is.is(403)));
}
public void should_return401or403_when_makingHttpRequestWithoutToken(String partitionId) throws Exception {
ClientResponse response = descriptor.run(partitionId, "");
assertThat(error(response.getEntity(String.class)), response.getStatus(), anyOf(Is.is(401), Is.is(403)));
}
protected String error(String body) {
return String.format("%s: %s %s %s", descriptor.getHttpMethod(), descriptor.getPath(), descriptor.getQuery(), body);
}
}
......@@ -23,11 +23,11 @@ public class AnthosTestUtils extends TestUtils {
@Override
public String getAccessToken() {
return tokenProvider.getToken();
return "Bearer " + tokenProvider.getToken();
}
@Override
public String getNoAccessToken() {
return tokenProvider.getNoAccessToken();
return "Bearer " + tokenProvider.getNoAccessToken();
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment