-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/639 handle policy expiration #1041
Changes from 3 commits
3b6739f
30c995a
88b7fd5
e292065
e1eb275
81d839a
ef77bc0
fc5f75b
8efea7e
32536c8
e86bfba
1059d7e
19fc8e9
5568cbf
fa8349b
bf9db9f
6540dd2
8e229fd
932eedc
1d7215e
5659c08
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2024 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
********************************************************************************/ | ||
package org.eclipse.tractusx.traceability.integration.notification.investigation; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import io.restassured.http.ContentType; | ||
import lombok.val; | ||
import notification.request.NotificationSeverityRequest; | ||
import notification.request.NotificationTypeRequest; | ||
import notification.request.StartNotificationRequest; | ||
import org.eclipse.tractusx.traceability.assets.domain.asbuilt.repository.AssetAsBuiltRepository; | ||
import org.eclipse.tractusx.traceability.common.request.OwnPageable; | ||
import org.eclipse.tractusx.traceability.common.request.PageableFilterRequest; | ||
import org.eclipse.tractusx.traceability.common.request.SearchCriteriaRequestParam; | ||
import org.eclipse.tractusx.traceability.integration.IntegrationTestSpecification; | ||
import org.eclipse.tractusx.traceability.integration.common.support.AssetsSupport; | ||
import org.eclipse.tractusx.traceability.integration.common.support.DiscoveryFinderSupport; | ||
import org.eclipse.tractusx.traceability.integration.common.support.EdcSupport; | ||
import org.eclipse.tractusx.traceability.integration.common.support.IrsApiSupport; | ||
import org.eclipse.tractusx.traceability.integration.common.support.NotificationApiSupport; | ||
import org.eclipse.tractusx.traceability.integration.common.support.NotificationMessageSupport; | ||
import org.eclipse.tractusx.traceability.integration.common.support.NotificationSupport; | ||
import org.eclipse.tractusx.traceability.integration.common.support.OAuth2ApiSupport; | ||
import org.eclipse.tractusx.traceability.notification.domain.notification.service.NotificationReceiverService; | ||
import org.hamcrest.Matchers; | ||
import org.jose4j.lang.JoseException; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.test.context.TestPropertySource; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.eclipse.tractusx.traceability.common.security.JwtRole.SUPERVISOR; | ||
|
||
@TestPropertySource(properties = "traceability.validUntil=2020-07-04T16:01:05.309Z") | ||
public class InvestigationPolicyExpirationIT extends IntegrationTestSpecification { | ||
@Autowired | ||
NotificationReceiverService notificationReceiverService; | ||
@Autowired | ||
AssetsSupport assetsSupport; | ||
@Autowired | ||
NotificationMessageSupport notificationMessageSupport; | ||
@Autowired | ||
NotificationSupport notificationSupport; | ||
@Autowired | ||
AssetAsBuiltRepository assetAsBuiltRepository; | ||
@Autowired | ||
NotificationApiSupport notificationApiSupport; | ||
@Autowired | ||
EdcSupport edcSupport; | ||
|
||
@Autowired | ||
DiscoveryFinderSupport discoveryFinderSupport; | ||
|
||
@Autowired | ||
OAuth2ApiSupport oauth2ApiSupport; | ||
|
||
@Autowired | ||
IrsApiSupport irsApiSupport; | ||
|
||
ObjectMapper objectMapper; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
objectMapper = new ObjectMapper(); | ||
} | ||
|
||
@Test | ||
void shouldNotApproveInvestigationStatus_whenPolicyIsExpired() throws JoseException, com.fasterxml.jackson.core.JsonProcessingException { | ||
// given | ||
irsApiSupport.irsApiReturnsPolicies(); | ||
discoveryFinderSupport.discoveryFinderWillReturnEndpointAddress(); | ||
discoveryFinderSupport.discoveryFinderWillReturnConnectorEndpoints(); | ||
oauth2ApiSupport.oauth2ApiReturnsDtrToken(); | ||
edcSupport.performSupportActionsForAsyncNotificationMessageExecutor(); | ||
List<String> partIds = List.of( | ||
"urn:uuid:fe99da3d-b0de-4e80-81da-882aebcca978", // BPN: BPNL00000003AYRE | ||
"urn:uuid:0ce83951-bc18-4e8f-892d-48bad4eb67ef" // BPN: BPNL00000003AXS3 | ||
); | ||
String description = "at least 15 characters long investigation description"; | ||
|
||
assetsSupport.defaultAssetsStored(); | ||
val startInvestigationRequest = StartNotificationRequest.builder() | ||
.affectedPartIds(partIds) | ||
.description(description) | ||
.severity(NotificationSeverityRequest.MINOR) | ||
.type(NotificationTypeRequest.INVESTIGATION) | ||
.receiverBpn("BPNL00000003CNKC") | ||
.build(); | ||
|
||
// when | ||
val investigationId = notificationApiSupport.createNotificationRequest_withDefaultAssetsStored(oAuth2Support.jwtAuthorization(SUPERVISOR), startInvestigationRequest, 201); | ||
|
||
|
||
notificationSupport.assertInvestigationsSize(1); | ||
|
||
given() | ||
.contentType(ContentType.JSON) | ||
.header(oAuth2Support.jwtAuthorization(SUPERVISOR)) | ||
.when() | ||
.post("/api/notifications/{investigationId}/approve", investigationId) | ||
.then() | ||
.log().all() | ||
.statusCode(503); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 503? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the current implementation in case something fails, when trying to send notifications. Maybe HTTP 500 suits better There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my opinion a 400 would match better, since the policy is part of a notification negotiation. |
||
|
||
// then | ||
given() | ||
.header(oAuth2Support.jwtAuthorization(SUPERVISOR)) | ||
.body(new PageableFilterRequest(new OwnPageable(0, 10, Collections.emptyList()), new SearchCriteriaRequestParam(List.of("channel,EQUAL,SENDER,AND")))) | ||
.contentType(ContentType.JSON) | ||
.when() | ||
.post("/api/notifications/filter") | ||
.then() | ||
.log().all() | ||
.statusCode(200) | ||
.body("page", Matchers.is(0)) | ||
.body("pageSize", Matchers.is(10)) | ||
.body("content", Matchers.hasSize(1)) | ||
.body("content[0].sendTo", Matchers.is(Matchers.not(Matchers.blankOrNullString()))) | ||
.body("content[0].messages[0].errorMessage", Matchers.is("Failed to negotiate contract agreement: Consumption of asset '40276218-e31b-4c35-a7c8-017e8edb702e' is not permitted as the required catalog offer policies are expired.")) | ||
.body("content[0].messages[1].errorMessage", Matchers.is("Failed to negotiate contract agreement: Consumption of asset '40276218-e31b-4c35-a7c8-017e8edb702e' is not permitted as the required catalog offer policies are expired.")); | ||
|
||
notificationMessageSupport.assertMessageSize(2); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently the issue is that on the getCatalog call within the class NotificationsEdcFacade between line 157 and 164 we filter out all elements which are invalid.
Instead of filtering them out we need to catch them in a different exception.
e.g. PolicyExpiredException
This policy then will be cached again in EdcNotificationServiceImpl#handleSendingNotification, where we need to enrich the error message into the notification.
At the end we will have the info in the frontend that it was not possible to send it out due to policy issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PolicyCheckerService was adapted according to the requirements in issue #639. Please see eclipse-tractusx/item-relationship-service@6e8880b#diff-b63cc42711ba192e7a2ff818eaad3bf34984ebf1f30d53b2f5df2abfa468e623 fore reference.
This handles "NotificationsEdcFacade between line 157 and 164".
UsagePolicyExpiredException was also added: eclipse-tractusx/item-relationship-service@6e8880b#diff-3db264f1f24f39482d77c13221eaba18eba63de4620a7598ba4a1d404623e8ce
This is thrown, if the policy is expired during contract negotiation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now the filter is gone. That is good. Still some things missing.
When the client library throws an exception within the contract negotiation (the point were you changed the exceptions) it will throw an exception and based on the logic of trace-x it will be catched and always mapped to the generic "NegotiationException" which is for our usage not enough.
We need to know if the policy was expired, or the policy constraints are incorrect or the policy is missing.
Therefore please catch those exceptions and pass them to the errorEnricher. To make sure we have that information in the frontend available.
If this is not manageable within the story - please recheck with product owner if new issue can be created for following up on that one.