Skip to content
Snippets Groups Projects
Commit e448b152 authored by Komal Makkar's avatar Komal Makkar
Browse files

adding auth mechanism for pubsub request

parent 4b232896
No related branches found
No related tags found
1 merge request!57Authz addition for Event Grid
Pipeline #21961 failed
......@@ -21,15 +21,16 @@ import com.microsoft.aad.adal4j.ClientCredential;
import org.apache.http.HttpStatus;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.search.IdToken;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.common.provider.interfaces.IJwtCache;
import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory;
import org.opengroup.osdu.core.common.util.IServiceAccountJwtClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.net.MalformedURLException;
import java.util.concurrent.*;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
@Component
public class ServiceAccountJwtAzureClientImpl implements IServiceAccountJwtClient {
......@@ -37,15 +38,10 @@ public class ServiceAccountJwtAzureClientImpl implements IServiceAccountJwtClien
@Autowired
private AppProperties config;
@Autowired
private ITenantFactory tenantInfoServiceProvider;
@Autowired
private IJwtCache tenantJwtCache;
public String getIdToken(String tenantName) {
String ACCESS_TOKEN = "";
ExecutorService service = null;
......@@ -97,4 +93,3 @@ public class ServiceAccountJwtAzureClientImpl implements IServiceAccountJwtClien
return ACCESS_TOKEN;
}
}
......@@ -19,11 +19,9 @@ import com.auth0.jwt.algorithms.Algorithm;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
import org.mockito.junit.MockitoJUnitRunner;
import org.opengroup.osdu.notification.provider.azure.util.AppProperties;
import org.opengroup.osdu.notification.provider.azure.util.AzureServiceAccountValidatorImpl;
......@@ -34,7 +32,6 @@ import static org.mockito.MockitoAnnotations.initMocks;
public class AzureServiceAccountValidatorImplTest {
private static String eventGridId = "eventgridid";
private static String invalidJWT = "invalidJWT";
@Mock
private AppProperties appProperties;
......
......@@ -26,8 +26,6 @@ import org.mockito.junit.MockitoJUnitRunner;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.search.IdToken;
import org.opengroup.osdu.core.common.model.tenant.TenantInfo;
import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory;
import org.opengroup.osdu.notification.provider.azure.cache.JwtCache;
import org.opengroup.osdu.notification.provider.azure.util.AppProperties;
import org.opengroup.osdu.notification.provider.azure.util.ServiceAccountJwtAzureClientImpl;
......@@ -36,8 +34,8 @@ import java.util.concurrent.ExecutorService;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.MockitoAnnotations.initMocks;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.initMocks;
@RunWith(MockitoJUnitRunner.class)
public class ServiceAccountClientImplTest {
......@@ -45,12 +43,6 @@ public class ServiceAccountClientImplTest {
final String tenantName = "Test Tenant";
final String validToken = "validToken";
@Mock
private ITenantFactory tenantInfoServiceProvider;
@Mock
private TenantInfo tenantInfo;
@Mock
private IdToken idToken;
......@@ -73,29 +65,9 @@ public class ServiceAccountClientImplTest {
@Before
public void setup() {
initMocks(this);
when(tenantInfo.getName()).thenReturn(tenantName);
when(this.tenantInfoServiceProvider.getTenantInfo(tenantName)).thenReturn(tenantInfo);
idToken = IdToken.builder().tokenValue(validToken).expirationTimeMillis(System.currentTimeMillis() + 10000000L).build();
}
@Test
public void should_throwAppException_getIdTokenTest() {
// Set up
when(this.tenantInfoServiceProvider.getTenantInfo(tenantName)).thenReturn(null);
try {
// Act
sut.getIdToken(tenantName);
// Assert
fail("Should throw exception");
} catch (AppException e) {
Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, e.getError().getCode());
Assert.assertEquals("Invalid tenant Name from azure", e.getError().getMessage());
} catch (Exception e) {
fail("Should not throw this exception" + e.getMessage());
}
}
@Test
public void should_getTokenFromCache_getIdTokenTest() {
// SetUp
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment