44
55namespace Keboola \JobQueueInternalClient \Tests \ObjectEncryptor ;
66
7+ use InvalidArgumentException ;
78use Keboola \JobQueueInternalClient \JobFactory \JobObjectEncryptor ;
89use Keboola \ObjectEncryptor \ObjectEncryptor ;
910use Keboola \PermissionChecker \BranchType ;
1011use PHPUnit \Framework \TestCase ;
1112
1213class JobObjectEncryptorTest extends TestCase
1314{
14- public function testEncryptWithoutBranch (): void
15+ public function testEncryptWithoutBranchAndNoProtectedFeature (): void
1516 {
1617 $ internalEncryptor = $ this ->createMock (ObjectEncryptor::class);
1718 $ internalEncryptor ->expects (self ::once ())
@@ -21,12 +22,45 @@ public function testEncryptWithoutBranch(): void
2122 ;
2223
2324 $ encryptor = new JobObjectEncryptor ($ internalEncryptor );
24- $ result = $ encryptor ->encrypt ('data ' , 'componentId ' , 'projectId ' , null );
25+ $ result = $ encryptor ->encrypt ('data ' , 'componentId ' , 'projectId ' , null , [] );
2526
2627 self ::assertSame ('encryptedData ' , $ result );
2728 }
2829
29- public function testEncryptWithBranch (): void
30+ public function testEncryptWithBranchAndNoProtectedFeature (): void
31+ {
32+ $ internalEncryptor = $ this ->createMock (ObjectEncryptor::class);
33+ $ internalEncryptor ->expects (self ::once ())
34+ ->method ('encryptForProject ' )
35+ ->with ('data ' , 'componentId ' , 'projectId ' )
36+ ->willReturn ('encryptedData ' )
37+ ;
38+
39+ $ encryptor = new JobObjectEncryptor ($ internalEncryptor );
40+ $ result = $ encryptor ->encrypt ('data ' , 'componentId ' , 'projectId ' , BranchType::DEFAULT , []);
41+
42+ self ::assertSame ('encryptedData ' , $ result );
43+ }
44+
45+ public function testEncryptWithProtectedDefaultBranchFeatureAndNoBranch (): void
46+ {
47+ $ internalEncryptor = $ this ->createMock (ObjectEncryptor::class);
48+ $ internalEncryptor ->expects (self ::never ())
49+ ->method ('encryptForProject ' )
50+ ;
51+ $ internalEncryptor ->expects (self ::never ())
52+ ->method ('encryptForBranchType ' )
53+ ;
54+
55+ $ encryptor = new JobObjectEncryptor ($ internalEncryptor );
56+
57+ $ this ->expectException (InvalidArgumentException::class);
58+ $ this ->expectExceptionMessage ('Protected default branch feature is enabled, but branch type is not set. ' );
59+
60+ $ encryptor ->encrypt ('data ' , 'componentId ' , 'projectId ' , null , ['protected-default-branch ' ]);
61+ }
62+
63+ public function testEncryptWithProtectedDefaultBranchFeatureAndBranch (): void
3064 {
3165 $ internalEncryptor = $ this ->createMock (ObjectEncryptor::class);
3266 $ internalEncryptor ->expects (self ::once ())
@@ -36,7 +70,13 @@ public function testEncryptWithBranch(): void
3670 ;
3771
3872 $ encryptor = new JobObjectEncryptor ($ internalEncryptor );
39- $ result = $ encryptor ->encrypt ('data ' , 'componentId ' , 'projectId ' , BranchType::DEFAULT );
73+ $ result = $ encryptor ->encrypt (
74+ 'data ' ,
75+ 'componentId ' ,
76+ 'projectId ' ,
77+ BranchType::DEFAULT ,
78+ ['protected-default-branch ' ],
79+ );
4080
4181 self ::assertSame ('encryptedData ' , $ result );
4282 }
0 commit comments