Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Open Subsurface Data Universe Software
Platform
System
Lib
cloud
azure
OS Core Lib Azure
Commits
d86abc07
Commit
d86abc07
authored
Dec 04, 2020
by
Aalekh Jain
Committed by
Kishore Battula
Dec 04, 2020
Browse files
Added UTs for sas token methods
parent
dca0554f
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/test/java/org/opengroup/osdu/azure/blobstorage/BlobStoreTest.java
View file @
d86abc07
...
...
@@ -23,6 +23,9 @@ import com.azure.storage.blob.models.BlobCopyInfo;
import
com.azure.storage.blob.models.BlobErrorCode
;
import
com.azure.storage.blob.models.BlobStorageException
;
import
com.azure.storage.blob.models.BlockBlobItem
;
import
com.azure.storage.blob.sas.BlobContainerSasPermission
;
import
com.azure.storage.blob.sas.BlobSasPermission
;
import
com.azure.storage.blob.sas.BlobServiceSasSignatureValues
;
import
com.azure.storage.blob.specialized.BlockBlobClient
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
...
...
@@ -36,8 +39,11 @@ import org.opengroup.osdu.core.common.model.http.AppException;
import
java.io.ByteArrayOutputStream
;
import
java.time.Duration
;
import
java.time.OffsetDateTime
;
import
java.util.List
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertNull
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
fail
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
Mockito
.*;
...
...
@@ -84,6 +90,9 @@ public class BlobStoreTest {
@Mock
private
PollResponse
<
BlobCopyInfo
>
pollResponse
;
@Mock
private
BlobSasPermission
blobSasPermission
;
@BeforeEach
void
init
()
{
initMocks
(
this
);
...
...
@@ -258,6 +267,65 @@ public class BlobStoreTest {
assertEquals
(
copyInfo
,
null
);
}
@Test
public
void
getSasToken_NullSasTokenObtained
()
{
int
expiryDays
=
1
;
OffsetDateTime
expiryTime
=
OffsetDateTime
.
now
().
plusDays
(
expiryDays
);
String
sasToken
=
blobStore
.
getSasToken
(
PARTITION_ID
,
FILE_PATH
,
STORAGE_CONTAINER_NAME
,
expiryTime
,
blobSasPermission
);
assertNull
(
sasToken
);
}
@Test
public
void
getSasToken_whenBlobSasTokenProvided_thenReturnsValidSasToken
()
{
String
blobSasToken
=
"blobSasToken"
;
doReturn
(
blobSasToken
).
when
(
blockBlobClient
).
generateSas
(
any
(
BlobServiceSasSignatureValues
.
class
));
int
expiryDays
=
1
;
OffsetDateTime
expiryTime
=
OffsetDateTime
.
now
().
plusDays
(
expiryDays
);
BlobSasPermission
blobSasPermission
=
(
new
BlobSasPermission
()).
setReadPermission
(
true
).
setCreatePermission
(
true
);
String
obtainedBlobSasToken
=
blobStore
.
getSasToken
(
PARTITION_ID
,
FILE_PATH
,
STORAGE_CONTAINER_NAME
,
expiryTime
,
blobSasPermission
);
ArgumentCaptor
<
BlobServiceSasSignatureValues
>
blobServiceSasSignatureValuesArgumentCaptor
=
ArgumentCaptor
.
forClass
(
BlobServiceSasSignatureValues
.
class
);
verify
(
blockBlobClient
).
generateSas
(
blobServiceSasSignatureValuesArgumentCaptor
.
capture
());
assertEquals
(
blobSasPermission
.
toString
(),
blobServiceSasSignatureValuesArgumentCaptor
.
getValue
().
getPermissions
());
assertEquals
(
expiryTime
,
blobServiceSasSignatureValuesArgumentCaptor
.
getValue
().
getExpiryTime
());
assertEquals
(
blobSasToken
,
obtainedBlobSasToken
);
}
@Test
public
void
generatePreSignedURLForContainer_NullPreSignedTokenObtained
()
{
int
expiryDays
=
1
;
OffsetDateTime
expiryTime
=
OffsetDateTime
.
now
().
plusDays
(
expiryDays
);
BlobContainerSasPermission
blobContainerSasPermission
=
(
new
BlobContainerSasPermission
()).
setReadPermission
(
true
).
setCreatePermission
(
true
);
String
obtainedPreSignedUrl
=
blobStore
.
generatePreSignedURL
(
PARTITION_ID
,
STORAGE_CONTAINER_NAME
,
expiryTime
,
blobContainerSasPermission
);
assertEquals
(
"null?null"
,
obtainedPreSignedUrl
);
}
@Test
public
void
generatePreSignedURLForContainer_whenContainerPreSignedUrl_thenReturnsValidSasToken
()
{
String
containerSasToken
=
"containerSasToken"
;
String
containerUrl
=
"containerUrl"
;
String
containerPreSignedUrl
=
containerUrl
+
"?"
+
containerSasToken
;
doReturn
(
containerSasToken
).
when
(
blobContainerClient
).
generateSas
(
any
(
BlobServiceSasSignatureValues
.
class
));
doReturn
(
containerUrl
).
when
(
blobContainerClient
).
getBlobContainerUrl
();
int
expiryDays
=
1
;
OffsetDateTime
expiryTime
=
OffsetDateTime
.
now
().
plusDays
(
expiryDays
);
BlobContainerSasPermission
blobContainerSasPermission
=
(
new
BlobContainerSasPermission
()).
setReadPermission
(
true
).
setCreatePermission
(
true
);
String
obtainedPreSignedUrl
=
blobStore
.
generatePreSignedURL
(
PARTITION_ID
,
STORAGE_CONTAINER_NAME
,
expiryTime
,
blobContainerSasPermission
);
ArgumentCaptor
<
BlobServiceSasSignatureValues
>
blobServiceSasSignatureValuesArgumentCaptor
=
ArgumentCaptor
.
forClass
(
BlobServiceSasSignatureValues
.
class
);
verify
(
blobContainerClient
).
generateSas
(
blobServiceSasSignatureValuesArgumentCaptor
.
capture
());
assertEquals
(
blobContainerSasPermission
.
toString
(),
blobServiceSasSignatureValuesArgumentCaptor
.
getValue
().
getPermissions
());
assertEquals
(
expiryTime
,
blobServiceSasSignatureValuesArgumentCaptor
.
getValue
().
getExpiryTime
());
assertEquals
(
containerPreSignedUrl
,
obtainedPreSignedUrl
);
}
private
BlobStorageException
mockStorageException
(
BlobErrorCode
errorCode
)
{
BlobStorageException
mockException
=
mock
(
BlobStorageException
.
class
);
lenient
().
when
(
mockException
.
getErrorCode
()).
thenReturn
(
errorCode
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment