-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a82f656
commit 004bc11
Showing
12 changed files
with
287 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AzureOss\Storage\Tests\Blob\Unit; | ||
|
||
use AzureOss\Storage\Blob\Sas\BlobContainerSasPermissions; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class BlobContainerSasPermissionsTest extends TestCase | ||
{ | ||
#[Test] | ||
public function to_string_works(): void | ||
{ | ||
$permissions = new BlobContainerSasPermissions(); | ||
|
||
self::assertEquals("", (string) $permissions); | ||
|
||
$permissions = new BlobContainerSasPermissions(read: true, delete: true); | ||
|
||
self::assertEquals("rd", (string) $permissions); | ||
|
||
$permissions = new BlobContainerSasPermissions( | ||
read: true, | ||
add: true, | ||
create: true, | ||
write: true, | ||
delete: true, | ||
deleteVersion: true, | ||
list: true, | ||
find: true, | ||
move: true, | ||
execute: true, | ||
ownership: true, | ||
permissions: true, | ||
setImmutabilityPolicy: true, | ||
); | ||
|
||
self::assertEquals("racwdxlfmeopi", (string) $permissions); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AzureOss\Storage\Tests\Blob\Unit; | ||
|
||
use AzureOss\Storage\Blob\Sas\BlobSasPermissions; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class BlobSasPermissionsTest extends TestCase | ||
{ | ||
#[Test] | ||
public function to_string_works(): void | ||
{ | ||
$permissions = new BlobSasPermissions(); | ||
|
||
self::assertEquals("", (string) $permissions); | ||
|
||
$permissions = new BlobSasPermissions(read: true, delete: true); | ||
|
||
self::assertEquals("rd", (string) $permissions); | ||
|
||
$permissions = new BlobSasPermissions( | ||
read: true, | ||
add: true, | ||
create: true, | ||
write: true, | ||
delete: true, | ||
deleteVersion: true, | ||
permanentDelete: true, | ||
tags: true, | ||
list: true, | ||
move: true, | ||
execute: true, | ||
ownership: true, | ||
permissions: true, | ||
setImmutabilityPolicy: true, | ||
); | ||
|
||
self::assertEquals("racwdxyltmeopi", (string) $permissions); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AzureOss\Storage\Tests\Common\Unit; | ||
|
||
use AzureOss\Storage\Common\Sas\AccountSasPermissions; | ||
use PHPUnit\Framework\TestCase; | ||
use PHPUnit\Framework\Attributes\Test; | ||
|
||
class AccountSasPermissionsTest extends TestCase | ||
{ | ||
#[Test] | ||
public function to_string_works(): void | ||
{ | ||
$permissions = new AccountSasPermissions(); | ||
|
||
self::assertEquals("", (string) $permissions); | ||
|
||
$permissions = new AccountSasPermissions(read: true, delete: true, add: true); | ||
|
||
self::assertEquals("rda", (string) $permissions); | ||
|
||
$permissions = new AccountSasPermissions( | ||
read: true, | ||
write: true, | ||
delete: true, | ||
permanentDelete: true, | ||
list: true, | ||
add: true, | ||
create: true, | ||
update: true, | ||
process: true, | ||
tags: true, | ||
filter: true, | ||
setImmutabilityPolicy: true, | ||
); | ||
|
||
self::assertEquals("rwdylacuptfi", (string) $permissions); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AzureOss\Storage\Tests\Common\Unit; | ||
|
||
use AzureOss\Storage\Common\Sas\AccountSasResourceTypes; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class AccountSasResourceTypesTest extends TestCase | ||
{ | ||
#[Test] | ||
public function to_string_works(): void | ||
{ | ||
$resource = new AccountSasResourceTypes(); | ||
|
||
self::assertEquals("", (string) $resource); | ||
|
||
$resource = new AccountSasResourceTypes(container: true); | ||
|
||
self::assertEquals("c", (string) $resource); | ||
|
||
$resource = new AccountSasResourceTypes(service: true, container: true, object: true); | ||
|
||
self::assertEquals("sco", (string) $resource); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AzureOss\Storage\Tests\Common\Unit; | ||
|
||
use AzureOss\Storage\Common\Sas\AccountSasServices; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class AccountSasServicesTest extends TestCase | ||
{ | ||
#[Test] | ||
public function to_string_works(): void | ||
{ | ||
$services = new AccountSasServices(); | ||
|
||
self::assertEquals("", (string) $services); | ||
|
||
$services = new AccountSasServices(queue: true); | ||
|
||
self::assertEquals("q", (string) $services); | ||
|
||
$services = new AccountSasServices(blob: true, queue: true, table: true, file: true); | ||
|
||
self::assertEquals("bqtf", (string) $services); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AzureOss\Storage\Tests\Common\Unit; | ||
|
||
use AzureOss\Storage\Common\Sas\SasIpRange; | ||
use PHPUnit\Framework\TestCase; | ||
use PHPUnit\Framework\Attributes\Test; | ||
|
||
class SasIpRangeTest extends TestCase | ||
{ | ||
#[Test] | ||
public function to_string_works_with_start_and_end(): void | ||
{ | ||
$ipRange = new SasIpRange("0.0.0.0", "255.255.255.255"); | ||
|
||
self::assertEquals("0.0.0.0-255.255.255.255", (string) $ipRange); | ||
} | ||
|
||
#[Test] | ||
public function to_string_works_with_only_start(): void | ||
{ | ||
$ipRange = new SasIpRange("192.168.0.1"); | ||
|
||
self::assertEquals("192.168.0.1", (string) $ipRange); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace AzureOss\Storage\Tests\Common\Unit; | ||
|
||
use AzureOss\Storage\Common\Auth\StorageSharedKeyCredential; | ||
use AzureOss\Storage\Common\Exceptions\InvalidAccountKeyException; | ||
use PHPUnit\Framework\Attributes\Test; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class StorageSharedKeyCredentialTest extends TestCase | ||
{ | ||
#[Test] | ||
public function compute_hmacs_sha256_works(): void | ||
{ | ||
$credential = new StorageSharedKeyCredential( | ||
"devstoreaccount1", | ||
"Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==", | ||
); | ||
|
||
self::assertEquals("Vir+MCz8c2dq+mnnEDMDF3s6vDBzCyY6WRzlblvWsgw=", $credential->computeHMACSHA256("Hello, world!")); | ||
} | ||
|
||
#[Test] | ||
public function compute_hmacs_sha256_throws_when_account_key_is_invalid(): void | ||
{ | ||
$this->expectException(InvalidAccountKeyException::class); | ||
|
||
$credential = new StorageSharedKeyCredential( | ||
"devstoreaccount1", | ||
"This_is_not_base64!", | ||
); | ||
|
||
$credential->computeHMACSHA256("Hello, world!"); | ||
} | ||
} |