diff --git a/core/platform-common/pom.xml b/core/platform-common/pom.xml index 92ff7f9491..0c6bcab3fe 100644 --- a/core/platform-common/pom.xml +++ b/core/platform-common/pom.xml @@ -114,7 +114,7 @@ org.sunbird cloud-store-sdk - 1.4.3 + 1.4.4 com.sun.jersey diff --git a/core/platform-common/src/main/java/org/sunbird/util/CloudStorageUtil.java b/core/platform-common/src/main/java/org/sunbird/util/CloudStorageUtil.java index dceb38ff75..c930eeccaf 100644 --- a/core/platform-common/src/main/java/org/sunbird/util/CloudStorageUtil.java +++ b/core/platform-common/src/main/java/org/sunbird/util/CloudStorageUtil.java @@ -30,16 +30,16 @@ public static String upload( public static String getSignedUrl( String storageType, String container, String objectKey) { IStorageService storageService = getStorageService(storageType); - return getSignedUrl(storageService, container, objectKey); + return getSignedUrl(storageService, container, objectKey,storageType); } public static String getSignedUrl( IStorageService storageService, String container, - String objectKey) { + String objectKey,String cloudType) { int timeoutInSeconds = getTimeoutInSeconds(); - return storageService.getSignedURL( - container, objectKey, Some.apply(timeoutInSeconds), Some.apply("r")); + return storageService.getSignedURLV2( + container, objectKey, Some.apply(timeoutInSeconds), Some.apply("r"), Some.apply("application/pdf")); } private static IStorageService getStorageService(String storageType) { diff --git a/core/platform-common/src/main/resources/externalresource.properties b/core/platform-common/src/main/resources/externalresource.properties index 12df4613f2..097af1a741 100644 --- a/core/platform-common/src/main/resources/externalresource.properties +++ b/core/platform-common/src/main/resources/externalresource.properties @@ -36,7 +36,7 @@ sunbird_otp_allowed_attempt=2 #Telemetry producer related info telemetry_pdata_id=local.sunbird.learning.service telemetry_pdata_pid=learning-service -telemetry_pdata_ver=5.1.0 +telemetry_pdata_ver=5.2.0 #elastic search top n result count for telemetry searchTopN=5 ekstep.channel.update.api.url=/channel/v3/update diff --git a/core/platform-common/src/test/java/org/sunbird/util/CloudStorageUtilTest.java b/core/platform-common/src/test/java/org/sunbird/util/CloudStorageUtilTest.java index 18fce8442e..975a5299cc 100644 --- a/core/platform-common/src/test/java/org/sunbird/util/CloudStorageUtilTest.java +++ b/core/platform-common/src/test/java/org/sunbird/util/CloudStorageUtilTest.java @@ -6,38 +6,33 @@ import static org.powermock.api.mockito.PowerMockito.when; import org.junit.Assert; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mockito; -import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.sunbird.cloud.storage.BaseStorageService; import org.sunbird.cloud.storage.factory.StorageServiceFactory; +import org.sunbird.keys.JsonKey; import scala.Option; @RunWith(PowerMockRunner.class) @PowerMockIgnore({ - "javax.management.*", - "javax.net.ssl.*", - "javax.security.*", - "jdk.internal.reflect.*" + "javax.management.*", + "javax.net.ssl.*", + "javax.security.*", + "jdk.internal.reflect.*" }) @PrepareForTest({StorageServiceFactory.class, CloudStorageUtil.class, PropertiesCache.class}) public class CloudStorageUtilTest { private static final String SIGNED_URL = "singedUrl"; private static final String UPLOAD_URL = "uploadUrl"; + private static final String PUT_SIGNED_URL = "gcpSignedUrl"; @Before public void initTest() { - PowerMockito.mockStatic(PropertiesCache.class); - PropertiesCache propertiesCache = mock(PropertiesCache.class); - when(PropertiesCache.getInstance()).thenReturn(propertiesCache); - PowerMockito.when(propertiesCache.getProperty(Mockito.anyString())).thenReturn("anyString"); - BaseStorageService service = mock(BaseStorageService.class); mockStatic(StorageServiceFactory.class); @@ -52,14 +47,46 @@ public void initTest() { Mockito.any(Option.class), Mockito.any(Option.class), Mockito.any(Option.class))) - .thenReturn(UPLOAD_URL); + .thenReturn(UPLOAD_URL); when(service.getSignedURL( Mockito.anyString(), Mockito.anyString(), Mockito.any(Option.class), Mockito.any(Option.class))) - .thenReturn(SIGNED_URL); + .thenReturn(SIGNED_URL); + + when(service.getPutSignedURL( + Mockito.anyString(), + Mockito.anyString(), + Mockito.any(Option.class), + Mockito.any(Option.class), + Mockito.any(Option.class))) + .thenReturn(PUT_SIGNED_URL); + + when(service.getSignedURLV2( + Mockito.eq("azurecontainer"), + Mockito.anyString(), + Mockito.any(Option.class), + Mockito.any(Option.class), + Mockito.any(Option.class))) + .thenReturn(SIGNED_URL); + + when(service.getSignedURLV2( + Mockito.eq("gcpcontainer"), + Mockito.anyString(), + Mockito.any(Option.class), + Mockito.any(Option.class), + Mockito.any(Option.class))) + .thenReturn(PUT_SIGNED_URL); + + when(service.getSignedURLV2( + Mockito.eq("awscontainer"), + Mockito.anyString(), + Mockito.any(Option.class), + Mockito.any(Option.class), + Mockito.any(Option.class))) + .thenReturn(SIGNED_URL); } catch (Exception e) { Assert.fail(e.getMessage()); @@ -67,17 +94,27 @@ public void initTest() { } @Test - // @Ignore public void testUploadSuccess() { String result = - CloudStorageUtil.upload("azure", "container", "key", "/file/path"); + CloudStorageUtil.upload("azure", "container", "key", "/file/path"); assertTrue(UPLOAD_URL.equals(result)); } @Test - @Ignore - public void testGetSignedUrlSuccess() { - String signedUrl = CloudStorageUtil.getSignedUrl("azure", "container", "key"); + public void testGetSignedUrlAZURESuccess() { + String signedUrl = CloudStorageUtil.getSignedUrl("azure", "azurecontainer", "key"); + assertTrue(SIGNED_URL.equals(signedUrl)); + } + + @Test + public void testGetSignedUrlGCPSuccess() { + String signedUrl = CloudStorageUtil.getSignedUrl("gcloud", "gcpcontainer", "key"); + assertTrue(PUT_SIGNED_URL.equals(signedUrl)); + } + + @Test + public void testGetSignedUrlAWSSuccess() { + String signedUrl = CloudStorageUtil.getSignedUrl("aws", "awscontainer", "key"); assertTrue(SIGNED_URL.equals(signedUrl)); } }