|
17 | 17 | use OCA\Libresign\Db\IdentifyMethodMapper; |
18 | 18 | use OCA\Libresign\Db\SignRequest; |
19 | 19 | use OCA\Libresign\Db\SignRequestMapper; |
| 20 | +use OCA\Libresign\Enum\DocMdpLevel; |
20 | 21 | use OCA\Libresign\Enum\SignatureFlow; |
21 | 22 | use OCA\Libresign\Exception\LibresignException; |
22 | 23 | use OCA\Libresign\Handler\DocMdpHandler; |
|
33 | 34 | use OCA\Libresign\Service\IdentifyMethodService; |
34 | 35 | use OCA\Libresign\Service\Policy\Model\ResolvedPolicy; |
35 | 36 | use OCA\Libresign\Service\Policy\PolicyService; |
| 37 | +use OCA\Libresign\Service\Policy\Provider\DocMdp\DocMdpPolicy; |
36 | 38 | use OCA\Libresign\Service\Policy\Provider\Signature\SignatureFlowPolicy; |
37 | 39 | use OCA\Libresign\Service\RequestSignatureService; |
38 | 40 | use OCA\Libresign\Service\SequentialSigningService; |
@@ -1078,14 +1080,120 @@ public function testUpdateSignatureFlowIfAllowedStoresResolvedPolicySnapshotWhen |
1078 | 1080 | ], $file->getMetadata()); |
1079 | 1081 | } |
1080 | 1082 |
|
| 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 | + |
1081 | 1188 | private function createResolvedPolicy( |
1082 | | - string $effectiveValue, |
| 1189 | + mixed $effectiveValue, |
1083 | 1190 | string $sourceScope = 'system', |
1084 | 1191 | bool $canUseAsRequestOverride = true, |
1085 | 1192 | ?string $blockedBy = null, |
| 1193 | + string $policyKey = 'signature_flow', |
1086 | 1194 | ): ResolvedPolicy { |
1087 | 1195 | return (new ResolvedPolicy()) |
1088 | | - ->setPolicyKey('signature_flow') |
| 1196 | + ->setPolicyKey($policyKey) |
1089 | 1197 | ->setEffectiveValue($effectiveValue) |
1090 | 1198 | ->setSourceScope($sourceScope) |
1091 | 1199 | ->setCanUseAsRequestOverride($canUseAsRequestOverride) |
|
0 commit comments