Skip to content

Commit 20ad866

Browse files
committed
test(request): align request signature flow expectations
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 3fd69fc commit 20ad866

1 file changed

Lines changed: 110 additions & 2 deletions

File tree

tests/php/Unit/Service/RequestSignatureServiceTest.php

Lines changed: 110 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use OCA\Libresign\Db\IdentifyMethodMapper;
1818
use OCA\Libresign\Db\SignRequest;
1919
use OCA\Libresign\Db\SignRequestMapper;
20+
use OCA\Libresign\Enum\DocMdpLevel;
2021
use OCA\Libresign\Enum\SignatureFlow;
2122
use OCA\Libresign\Exception\LibresignException;
2223
use OCA\Libresign\Handler\DocMdpHandler;
@@ -33,6 +34,7 @@
3334
use OCA\Libresign\Service\IdentifyMethodService;
3435
use OCA\Libresign\Service\Policy\Model\ResolvedPolicy;
3536
use OCA\Libresign\Service\Policy\PolicyService;
37+
use OCA\Libresign\Service\Policy\Provider\DocMdp\DocMdpPolicy;
3638
use OCA\Libresign\Service\Policy\Provider\Signature\SignatureFlowPolicy;
3739
use OCA\Libresign\Service\RequestSignatureService;
3840
use OCA\Libresign\Service\SequentialSigningService;
@@ -1078,14 +1080,120 @@ public function testUpdateSignatureFlowIfAllowedStoresResolvedPolicySnapshotWhen
10781080
], $file->getMetadata());
10791081
}
10801082

1083+
public function testSetDocMdpLevelUsesResolvedPolicyValue(): void {
1084+
$file = new \OCA\Libresign\Db\File();
1085+
$this->policyService
1086+
->expects($this->once())
1087+
->method('resolveForUser')
1088+
->with(DocMdpPolicy::KEY, null, [])
1089+
->willReturn($this->createResolvedPolicy(
1090+
2,
1091+
policyKey: DocMdpPolicy::KEY,
1092+
));
1093+
1094+
self::invokePrivate($this->getService(), 'setDocMdpLevelFromPolicy', [
1095+
$file,
1096+
[],
1097+
]);
1098+
1099+
$this->assertSame(DocMdpLevel::CERTIFIED_FORM_FILLING, $file->getDocmdpLevelEnum());
1100+
}
1101+
1102+
public function testSetDocMdpLevelStoresResolvedPolicySnapshotInMetadata(): void {
1103+
$file = new \OCA\Libresign\Db\File();
1104+
$this->policyService
1105+
->expects($this->once())
1106+
->method('resolveForUser')
1107+
->with(DocMdpPolicy::KEY, null, [DocMdpPolicy::KEY => 3])
1108+
->willReturn($this->createResolvedPolicy(
1109+
3,
1110+
sourceScope: 'group',
1111+
policyKey: DocMdpPolicy::KEY,
1112+
));
1113+
1114+
self::invokePrivate($this->getService(), 'setDocMdpLevelFromPolicy', [
1115+
$file,
1116+
['docmdpLevel' => '3'],
1117+
]);
1118+
1119+
$this->assertSame([
1120+
'policy_snapshot' => [
1121+
'docmdp' => [
1122+
'effectiveValue' => 3,
1123+
'sourceScope' => 'group',
1124+
],
1125+
],
1126+
], $file->getMetadata());
1127+
}
1128+
1129+
public function testUpdateDocMdpLevelFromPolicyUpdatesFileWhenEffectiveValueChanges(): void {
1130+
$file = new \OCA\Libresign\Db\File();
1131+
$file->setUserId('john');
1132+
$file->setDocmdpLevelEnum(DocMdpLevel::NOT_CERTIFIED);
1133+
1134+
$this->policyService
1135+
->expects($this->once())
1136+
->method('resolveForUserId')
1137+
->with(DocMdpPolicy::KEY, 'john', [DocMdpPolicy::KEY => 1])
1138+
->willReturn($this->createResolvedPolicy(
1139+
1,
1140+
policyKey: DocMdpPolicy::KEY,
1141+
));
1142+
1143+
$this->fileService
1144+
->expects($this->once())
1145+
->method('update')
1146+
->with($this->identicalTo($file));
1147+
1148+
self::invokePrivate($this->getService(), 'updateDocMdpLevelFromPolicy', [
1149+
$file,
1150+
['docmdpLevel' => 1],
1151+
]);
1152+
1153+
$this->assertSame(DocMdpLevel::CERTIFIED_NO_CHANGES_ALLOWED, $file->getDocmdpLevelEnum());
1154+
}
1155+
1156+
public function testUpdateDocMdpLevelFromPolicyDoesNotPersistWhenNothingChangedAndSnapshotExists(): void {
1157+
$file = new \OCA\Libresign\Db\File();
1158+
$file->setUserId('john');
1159+
$file->setDocmdpLevelEnum(DocMdpLevel::CERTIFIED_FORM_FILLING);
1160+
$file->setMetadata([
1161+
'policy_snapshot' => [
1162+
'docmdp' => [
1163+
'effectiveValue' => 2,
1164+
'sourceScope' => 'system',
1165+
],
1166+
],
1167+
]);
1168+
1169+
$this->policyService
1170+
->expects($this->once())
1171+
->method('resolveForUserId')
1172+
->with(DocMdpPolicy::KEY, 'john', [])
1173+
->willReturn($this->createResolvedPolicy(
1174+
2,
1175+
policyKey: DocMdpPolicy::KEY,
1176+
));
1177+
1178+
$this->fileService
1179+
->expects($this->never())
1180+
->method('update');
1181+
1182+
self::invokePrivate($this->getService(), 'updateDocMdpLevelFromPolicy', [
1183+
$file,
1184+
[],
1185+
]);
1186+
}
1187+
10811188
private function createResolvedPolicy(
1082-
string $effectiveValue,
1189+
mixed $effectiveValue,
10831190
string $sourceScope = 'system',
10841191
bool $canUseAsRequestOverride = true,
10851192
?string $blockedBy = null,
1193+
string $policyKey = 'signature_flow',
10861194
): ResolvedPolicy {
10871195
return (new ResolvedPolicy())
1088-
->setPolicyKey('signature_flow')
1196+
->setPolicyKey($policyKey)
10891197
->setEffectiveValue($effectiveValue)
10901198
->setSourceScope($sourceScope)
10911199
->setCanUseAsRequestOverride($canUseAsRequestOverride)

0 commit comments

Comments
 (0)