• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

FIWARE / contract-management / #123

11 Nov 2026 09:45AM UTC coverage: 12.061% (+3.4%) from 8.71%
#123

Pull #36

web-flow
Merge branch 'main' into ticket-105/work
Pull Request #36: Ticket 105/work

1474 of 1515 new or added lines in 34 files covered. (97.29%)

4726 of 39184 relevant lines covered (12.06%)

0.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.59
/src/main/java/org/fiware/iam/til/TrustedIssuersListAdapter.java
1
package org.fiware.iam.til;
2

3
import io.micronaut.core.annotation.Nullable;
4
import io.micronaut.http.HttpResponse;
5
import io.micronaut.http.HttpStatus;
6
import io.micronaut.http.client.exceptions.HttpClientResponseException;
7
import io.micronaut.http.codec.CodecException;
8
import jakarta.inject.Singleton;
9
import lombok.RequiredArgsConstructor;
10
import lombok.extern.slf4j.Slf4j;
11
import org.fiware.iam.configuration.DataSpaceEventsProperties;
12
import org.fiware.iam.exception.FailureReason;
13
import org.fiware.iam.exception.TrustedIssuersException;
14
import org.fiware.iam.http.HttpResponses;
15
import org.fiware.iam.til.api.IssuerApiClient;
16
import org.fiware.iam.til.model.CredentialsVO;
17
import org.fiware.iam.til.model.IssuerScopeVO;
18
import org.fiware.iam.til.model.ProblemDetailsVO;
19
import org.fiware.iam.til.model.ScopeTypeVO;
20
import org.fiware.iam.til.model.TrustedIssuerVO;
21
import org.fiware.iam.til.model.TrustedIssuersListResponseVO;
22
import org.fiware.iam.tmforum.CredentialsConfigResolver;
23
import reactor.core.publisher.Mono;
24

25
import java.util.Collections;
26
import java.util.LinkedHashSet;
27
import java.util.List;
28
import java.util.Objects;
29
import java.util.Optional;
30
import java.util.Set;
31
import java.util.UUID;
32
import java.util.function.Supplier;
33
import java.util.stream.Stream;
34

35
/**
36
 * Grants and revokes credentials at the trusted-issuers-list on behalf of a product order, and grants, reads and revokes
37
 * data-space memberships for the participant-removed handling.
38
 * <p>
39
 * Every credential is attributed to the order that granted it - its <i>scope</i> - so that revoking
40
 * one order cannot remove a credential another order still requires. That matters as soon as two
41
 * products share configuration, which is the normal case once the configuration lives on a
42
 * {@code ServiceSpecification} several products are composed of.
43
 * <p>
44
 * Requires trusted-issuers-list {@code 0.9.0} or newer for the scope-addressed endpoints; what the membership calls need
45
 * beyond that is decided by the capability probes (see {@link TilCapabilities}). Failures are raised, never logged here.
46
 */
47
@Singleton
48
@RequiredArgsConstructor
49
@Slf4j
1 ✔
50
public class TrustedIssuersListAdapter {
51

52
    /**
53
     * Order grants are untyped: omitting the scope type addresses exactly the untyped grants of a scope,
54
     * never e.g. a data-space membership granted under the same id, and is understood by older lists too.
55
     */
56
    private static final ScopeTypeVO ORDER_SCOPE_TYPE = null;
1 ✔
57

58
    /**
59
     * Membership grants are typed, so they never collide with an order grant under the same id.
60
     */
61
    public static final ScopeTypeVO DATASPACE_MEMBERSHIP_SCOPE_TYPE = ScopeTypeVO.DATASPACE_MEMBERSHIP;
1 ✔
62

63
    // validation messages of TrustedIssuersListController (FIWARE/trusted-issuers-list), answered as ProblemDetails detail
64
    static final String SCOPE_TYPE_WITHOUT_SCOPE =
65
            "A scope type requires a scope - unscoped credentials cannot be addressed by type.";
66
    static final String UNSCOPED_WITH_SCOPE =
67
            "A scope cannot be combined with unscoped=true - it addresses either a grant or none.";
68

69
    /**
70
     * Issuer the unscoped probe addresses; the probe is rejected before the issuer is looked up, and matches nothing otherwise.
71
     */
72
    static final String PROBE_DID = "did:web:capability-probe.contract-management.invalid";
73

74
    private static final int FIRST_PAGE = 0;
75
    private static final int PROBE_PAGE_SIZE = 1;
76
    // answers that say nothing about the version of the list
77
    private static final Set<Integer> NO_VERSION_SIGNAL = Set.of(
1 ✔
78
            HttpStatus.UNAUTHORIZED.getCode(), HttpStatus.FORBIDDEN.getCode(),
1 ✔
79
            HttpStatus.REQUEST_TIMEOUT.getCode(), HttpStatus.TOO_MANY_REQUESTS.getCode());
1 ✔
80

81
    private final IssuerApiClient apiClient;
82
    private final DataSpaceEventsProperties properties;
83

84
    /**
85
     * Grant the credentials an order configures to the given issuer.
86
     * <p>
87
     * The grant replaces whatever the same order granted before, so a redelivered notification
88
     * converges instead of accumulating entries. The issuer is created by the trusted-issuers-list if
89
     * it is not known yet.
90
     *
91
     * @param issuerDid         the issuer to grant to
92
     * @param orderId           the order the credentials are granted by
93
     * @param credentialsConfig the resolved configuration, of which only the locally managed part is granted
94
     * @return whether the grant succeeded
95
     */
96
    public Mono<Boolean> allowIssuer(String issuerDid, String orderId,
97
            List<CredentialsConfigResolver.CredentialConfig> credentialsConfig) {
98

99
        List<CredentialsVO> credentialsVOS = filterLocalCredentialsVO(credentialsConfig);
1 ✔
100
        if (credentialsVOS.isEmpty()) {
1 ✔
101
            // nothing to grant locally - and creating an empty issuer entry would be misleading
102
            log.debug("Order {} grants no locally managed credential to {}.", orderId, issuerDid);
1 ✔
103
            return Mono.just(true);
1 ✔
104
        }
105

106
        // deferred, so the call is issued on subscription and a synchronous failure of the client is
107
        // signalled through the returned Mono like any other error
108
        List<String> credentialTypes = credentialsVOS.stream().map(CredentialsVO::getCredentialsType).toList();
1 ✔
109
        return Mono.defer(() -> apiClient.replaceCredentialsByScope(issuerDid, orderId, credentialsVOS, ORDER_SCOPE_TYPE))
1 ✔
110
                .onErrorMap(e -> new TrustedIssuersException(FailureReason.TIL_REJECTED_ISSUER,
1 ✔
111
                        "The trusted-issuers-list did not allow issuer %s the credentials %s for order %s.".formatted(
1 ✔
112
                                issuerDid, credentialTypes, orderId), e))
113
                .map(response -> {
1 ✔
114
                    log.debug("Order {}: the trusted-issuers-list answered the grant of {} to issuer {} with {}.",
1 ✔
115
                            orderId, credentialTypes, issuerDid, response.getStatus().getCode());
1 ✔
116
                    return HttpResponses.isSuccess(response);
1 ✔
117
                });
118
    }
119

120
    /**
121
     * Revoke everything the given order granted to the given issuer.
122
     * <p>
123
     * Deliberately does not resolve the order's configuration: what has to be revoked is what was
124
     * granted, and that is recorded at the trusted-issuers-list under the order's id. A specification
125
     * that changed - or became unreadable - since the grant therefore cannot prevent the revocation.
126
     * Credentials granted by another order, and credentials an operator manages by hand, are not
127
     * touched.
128
     *
129
     * @param issuerDid the issuer to revoke from
130
     * @param orderId   the order whose grants are revoked
131
     * @return the response of the trusted-issuers-list
132
     */
133
    public Mono<HttpResponse<?>> denyIssuer(String issuerDid, String orderId) {
134
        return Mono.defer(() -> apiClient.deleteCredentialsByScope(issuerDid, orderId, ORDER_SCOPE_TYPE, false))
1 ✔
135
                .<HttpResponse<?>>map(response -> {
1 ✔
136
                    log.debug("Order {}: revoked the credentials of issuer {} at the trusted-issuers-list.", orderId, issuerDid);
1 ✔
137
                    return response;
1 ✔
138
                })
139
                .onErrorResume(e -> {
1 ✔
140
                    if (e instanceof HttpClientResponseException hcr && hcr.getStatus() == HttpStatus.NOT_FOUND) {
1 ✔
141
                        // nothing was ever granted to that issuer, so there is nothing to revoke
142
                        log.debug("Issuer {} is unknown to the trusted-issuers-list, nothing to revoke for order {}.",
1 ✔
143
                                issuerDid, orderId);
144
                        return Mono.just(HttpResponse.noContent());
1 ✔
145
                    }
146
                    return Mono.error(new TrustedIssuersException(FailureReason.TIL_REJECTED_ISSUER,
1 ✔
147
                            "The trusted-issuers-list did not revoke the credentials of issuer %s for order %s.".formatted(issuerDid, orderId), e));
1 ✔
148
                });
149
    }
150

151
    /**
152
     * Read what the list holds for the issuer. Empty if the issuer is unknown.
153
     * <p>
154
     * Fails with {@code TIL_READ_FAILED} if the issuer exists but its scopes cannot be listed (the {@code /scopes}
155
     * endpoint is missing), or if the issuer changed between the two reads so that the counts contradict each other.
156
     */
157
    public Mono<Optional<HeldEntry>> heldEntry(String did) {
158
        return content(did).map(content -> content.map(IssuerContent::held));
1 ✔
159
    }
160

161
    /**
162
     * Read what the list holds for the issuer together with its credentials, from the same reads; as {@link #heldEntry}.
163
     */
164
    public Mono<Optional<IssuerContent>> content(String did) {
165
        return call(() -> apiClient.getIssuer(did))
1 ✔
166
                .map(response -> response.getBody()
1 ✔
167
                        .map(TrustedIssuerVO::getCredentials)
1 ✔
168
                        .<List<CredentialsVO>>map(List::copyOf)
1 ✔
169
                        .orElse(List.of()))
1 ✔
170
                .flatMap(credentials -> call(() -> apiClient.getIssuerScopes(did))
1 ✔
171
                        .onErrorMap(TrustedIssuersListAdapter::isNotFound, e -> new TrustedIssuersException(FailureReason.TIL_READ_FAILED,
1 ✔
172
                                "The trusted-issuers-list holds issuer %s but lists no scopes for it - its /scopes endpoint is missing.".formatted(did), e))
1 ✔
173
                        .map(response -> new IssuerContent(
1 ✔
174
                                toHeldEntry(did, credentials.size(), response.getBody().orElse(List.of())), credentials)))
1 ✔
175
                .map(Optional::of)
1 ✔
176
                .onErrorResume(TrustedIssuersListAdapter::isNotFound, e -> Mono.just(Optional.empty()))
1 ✔
177
                .onErrorMap(e -> !(e instanceof TrustedIssuersException), e -> new TrustedIssuersException(FailureReason.TIL_READ_FAILED,
1 ✔
178
                        "The trusted-issuers-list could not be read for issuer %s.".formatted(did), e));
1 ✔
179
    }
180

181
    /**
182
     * All issuers holding the grant. Fails rather than answer a partial list (more than max-pages, or inconsistent pages).
183
     */
184
    public Mono<Set<String>> issuersGrantedBy(String scope, ScopeTypeVO type) {
185
        return listIssuers(scope, type, "the issuers granted " + describe(scope, type));
1 ✔
186
    }
187

188
    /**
189
     * All issuers of the list, under the same completeness rules as {@link #issuersGrantedBy}.
190
     */
191
    public Mono<Set<String>> allIssuers() {
192
        return listIssuers(null, null, "all issuers");
1 ✔
193
    }
194

195
    /**
196
     * Revoke exactly the issuer's (scope, type) grant. An unknown issuer counts as done.
197
     */
198
    public Mono<Void> revokeGrant(String did, String scope, @Nullable ScopeTypeVO type) {
199
        return idempotentWrite(() -> apiClient.deleteCredentialsByScope(did, scope, type, false),
1 ✔
200
                "The trusted-issuers-list did not revoke the grant %s of issuer %s.".formatted(describe(scope, type), did));
1 ✔
201
    }
202

203
    /**
204
     * Revoke the issuer's unattributed credentials, keeping every grant. An unknown issuer counts as done.
205
     */
206
    public Mono<Void> revokeUnattributed(String did) {
207
        return idempotentWrite(() -> apiClient.deleteCredentialsByScope(did, null, null, true),
1 ✔
208
                "The trusted-issuers-list did not revoke the unattributed credentials of issuer %s.".formatted(did));
1 ✔
209
    }
210

211
    /**
212
     * Delete the issuer with everything it holds. An unknown issuer counts as done.
213
     */
214
    public Mono<Void> deleteIssuer(String did) {
215
        return idempotentWrite(() -> apiClient.deleteIssuerById(did),
1 ✔
216
                "The trusted-issuers-list did not delete issuer %s.".formatted(did));
1 ✔
217
    }
218

219
    /**
220
     * Grant the publisher's data-space membership, replacing what it granted before. The only place membership grants are
221
     * written; the issuer's other grants and unattributed credentials are left alone, even identical ones.
222
     */
223
    public Mono<Void> grantMembership(String did, String publisherId, List<CredentialsVO> credentials) {
224
        return call(() -> apiClient.replaceCredentialsByScope(did, publisherId, credentials, DATASPACE_MEMBERSHIP_SCOPE_TYPE))
1 ✔
225
                .then()
1 ✔
226
                .onErrorMap(e -> new TrustedIssuersException(FailureReason.TIL_REJECTED_ISSUER,
1 ✔
227
                        "The trusted-issuers-list did not grant issuer %s the membership %s.".formatted(
1 ✔
228
                                did, describe(publisherId, DATASPACE_MEMBERSHIP_SCOPE_TYPE)), e));
1 ✔
229
    }
230

231
    /**
232
     * Probe for typed scopes: a type filter without a scope is rejected with a specific message only by a list that knows types.
233
     */
234
    public Mono<TilCapability.State> probeTypedScopes() {
235
        return call(() -> apiClient.getIssuers(null, null, null, DATASPACE_MEMBERSHIP_SCOPE_TYPE))
1 ✔
236
                // the filter was ignored
237
                .map(response -> TilCapability.State.TOO_OLD)
1 ✔
238
                .onErrorResume(e -> Mono.just(classify(e, SCOPE_TYPE_WITHOUT_SCOPE)));
1 ✔
239
    }
240

241
    /**
242
     * Probe for unscoped addressing: a scope combined with unscoped=true is rejected before the issuer is looked up. On an
243
     * old list the random scope matches nothing, so the probe has no effect.
244
     */
245
    public Mono<TilCapability.State> probeUnscoped() {
246
        return call(() -> apiClient.deleteCredentialsByScope(PROBE_DID, UUID.randomUUID().toString(), null, true))
1 ✔
247
                .map(response -> TilCapability.State.TOO_OLD)
1 ✔
248
                .onErrorResume(e -> Mono.just(classify(e, UNSCOPED_WITH_SCOPE)));
1 ✔
249
    }
250

251
    /**
252
     * Probe for {@code GET /issuer/{did}/scopes} with an issuer that exists, since the list answers an unknown issuer there
253
     * with the same bare 404 as a missing route. PENDING on an empty list.
254
     */
255
    public Mono<TilCapability.State> probeScopesEndpoint() {
256
        return call(() -> apiClient.getIssuers(PROBE_PAGE_SIZE, FIRST_PAGE, null, null))
1 ✔
257
                .flatMap(response -> {
1 ✔
258
                    if (response.getStatus() != HttpStatus.OK) {
1 ✔
259
                        return Mono.just(classify(response.getStatus().getCode(), false));
1 ✔
260
                    }
261
                    return response.getBody()
1 ✔
262
                            .map(TrustedIssuersListResponseVO::getItems)
1 ✔
263
                            .flatMap(items -> items.stream().filter(Objects::nonNull).findFirst())
1 ✔
264
                            .map(this::probeScopesOf)
1 ✔
265
                            .orElseGet(() -> Mono.just(TilCapability.State.PENDING));
1 ✔
266
                })
267
                .onErrorResume(e -> Mono.just(classify(e, null)));
1 ✔
268
    }
269

270
    private Mono<TilCapability.State> probeScopesOf(String did) {
271
        return call(() -> apiClient.getIssuerScopes(did))
1 ✔
272
                .map(response -> response.getStatus() == HttpStatus.OK && response.getBody().isPresent()
1 ✔
273
                        ? TilCapability.State.SUPPORTED
1 ✔
274
                        : TilCapability.State.TOO_OLD)
1 ✔
275
                .onErrorResume(e -> {
1 ✔
276
                    if (isNotFound(e)) {
1 ✔
277
                        return probeIssuerFound(did);
1 ✔
278
                    }
279
                    // a body that is not a list of scopes, e.g. the page of a proxy
280
                    return Mono.just(e instanceof CodecException ? TilCapability.State.TOO_OLD : classify(e, null));
1 ✔
281
                });
282
    }
283

284
    private Mono<TilCapability.State> probeIssuerFound(String did) {
285
        return call(() -> apiClient.getIssuer(did))
1 ✔
286
                // the issuer exists, so the 404 came from a missing /scopes route
287
                .map(response -> TilCapability.State.TOO_OLD)
1 ✔
288
                // deleted between the reads, so the 404 proved nothing
289
                .onErrorResume(e -> Mono.just(isNotFound(e) ? TilCapability.State.UNVERIFIED : classify(e, null)));
1 ✔
290
    }
291

292
    private Mono<Set<String>> listIssuers(@Nullable String scope, @Nullable ScopeTypeVO type, String listing) {
293
        DataSpaceEventsProperties.ParticipantRemovedSettings settings = properties.getParticipantRemoved();
1 ✔
294
        int pageSize = settings.effectivePageSize();
1 ✔
295
        int maxPages = settings.effectiveMaxPages();
1 ✔
296
        return fetchPage(scope, type, FIRST_PAGE, pageSize, listing)
1 ✔
297
                .expand(page -> {
1 ✔
298
                    if (!page.hasNext(pageSize)) {
1 ✔
299
                        return Mono.empty();
1 ✔
300
                    }
301
                    if (page.number() + 1 >= maxPages) {
1 ✔
302
                        return Mono.error(incomplete(listing, "needs more than the %s pages allowed".formatted(maxPages)));
1 ✔
303
                    }
304
                    return fetchPage(scope, type, page.number() + 1, pageSize, listing);
1 ✔
305
                })
306
                .collectList()
1 ✔
307
                .map(pages -> distinctDids(pages, listing));
1 ✔
308
    }
309

310
    private Mono<Page> fetchPage(@Nullable String scope, @Nullable ScopeTypeVO type, int number, int pageSize, String listing) {
311
        return call(() -> apiClient.getIssuers(pageSize, number, scope, type))
1 ✔
312
                .map(response -> response.getBody()
1 ✔
313
                        .map(body -> new Page(number, body.getTotal(), Optional.ofNullable(body.getItems()).orElse(List.of())))
1 ✔
314
                        .orElseThrow(() -> incomplete(listing, "answered page %s without a body".formatted(number))))
1 ✔
315
                .onErrorMap(e -> !(e instanceof TrustedIssuersException), e -> new TrustedIssuersException(FailureReason.TIL_READ_FAILED,
1 ✔
316
                        "The trusted-issuers-list could not list page %s of %s.".formatted(number, listing), e));
1 ✔
317
    }
318

319
    private static Set<String> distinctDids(List<Page> pages, String listing) {
320
        Integer total = pages.get(0).total();
1 ✔
321
        if (total == null) {
1 ✔
322
            throw incomplete(listing, "answered without a total");
1 ✔
323
        }
324
        Set<String> dids = new LinkedHashSet<>();
1 ✔
325
        for (Page page : pages) {
1 ✔
326
            if (!total.equals(page.total())) {
1 ✔
327
                throw incomplete(listing, "answered a total of %s on page %s instead of %s".formatted(page.total(), page.number(), total));
1 ✔
328
            }
329
            if (page.items().stream().anyMatch(Objects::isNull)) {
1 ✔
NEW
330
                throw incomplete(listing, "answered an entry without a DID on page %s".formatted(page.number()));
×
331
            }
332
            dids.addAll(page.items());
1 ✔
333
        }
1 ✔
334
        if (dids.size() != total) {
1 ✔
335
            throw incomplete(listing, "ended with %s distinct DIDs instead of the total of %s".formatted(dids.size(), total));
1 ✔
336
        }
337
        return Collections.unmodifiableSet(dids);
1 ✔
338
    }
339

340
    private static TrustedIssuersException incomplete(String listing, String detail) {
341
        return new TrustedIssuersException(FailureReason.TIL_READ_FAILED,
1 ✔
342
                "The trusted-issuers-list listing of %s is incomplete: it %s.".formatted(listing, detail));
1 ✔
343
    }
344

345
    private static HeldEntry toHeldEntry(String did, int credentialCount, List<IssuerScopeVO> scopes) {
346
        List<HeldEntry.Grant> grants = scopes.stream()
1 ✔
347
                .map(scope -> new HeldEntry.Grant(scope.getScope(), scope.getScopeType(),
1 ✔
348
                        Optional.ofNullable(scope.getCredentialCount()).orElse(0)))
1 ✔
349
                .toList();
1 ✔
350
        int attributed = grants.stream().mapToInt(HeldEntry.Grant::count).sum();
1 ✔
351
        if (attributed > credentialCount) {
1 ✔
352
            throw new TrustedIssuersException(FailureReason.TIL_READ_FAILED,
1 ✔
353
                    "Issuer %s changed while it was read: it holds %s credentials, but its scopes attribute %s.".formatted(
1 ✔
354
                            did, credentialCount, attributed));
1 ✔
355
        }
356
        return new HeldEntry(did, grants, credentialCount - attributed);
1 ✔
357
    }
358

359
    private Mono<Void> idempotentWrite(Supplier<Mono<HttpResponse<Object>>> write, String failure) {
360
        return call(write)
1 ✔
361
                .then()
1 ✔
362
                .onErrorResume(TrustedIssuersListAdapter::isNotFound, e -> Mono.empty())
1 ✔
363
                .onErrorMap(e -> new TrustedIssuersException(FailureReason.TIL_REVOKE_FAILED, failure, e));
1 ✔
364
    }
365

366
    // issued on subscription, so a synchronous failure of the client is signalled through the Mono; a non-2xx answer
367
    // becomes an error like the one the http client raises
368
    private static <T> Mono<HttpResponse<T>> call(Supplier<Mono<HttpResponse<T>>> request) {
369
        return Mono.defer(request)
1 ✔
370
                .flatMap(response -> HttpResponses.isSuccess(response)
1 ✔
371
                        ? Mono.just(response)
1 ✔
372
                        : Mono.error(new HttpClientResponseException(
1 ✔
373
                                "The trusted-issuers-list answered " + response.getStatus().getCode(), response)));
1 ✔
374
    }
375

376
    private static boolean isNotFound(Throwable e) {
377
        return e instanceof HttpClientResponseException hcr && hcr.getResponse().code() == HttpStatus.NOT_FOUND.getCode();
1 ✔
378
    }
379

380
    /**
381
     * Decide a capability from the probe's error: a 400 carrying the expected message is SUPPORTED, any other definitive
382
     * answer TOO_OLD, everything that is no version signal (auth, throttling, 5xx, no answer) UNVERIFIED.
383
     */
384
    static TilCapability.State classify(Throwable e, @Nullable String expectedMessage) {
385
        if (e instanceof HttpClientResponseException hcr) {
1 ✔
386
            return classify(hcr.getResponse().code(), expectedMessage != null && mentions(hcr, expectedMessage));
1 ✔
387
        }
388
        return TilCapability.State.UNVERIFIED;
1 ✔
389
    }
390

391
    private static TilCapability.State classify(int status, boolean expectedRejection) {
392
        if (status == HttpStatus.BAD_REQUEST.getCode()) {
1 ✔
393
            return expectedRejection ? TilCapability.State.SUPPORTED : TilCapability.State.TOO_OLD;
1 ✔
394
        }
395
        if (NO_VERSION_SIGNAL.contains(status) || status >= HttpStatus.INTERNAL_SERVER_ERROR.getCode()) {
1 ✔
396
            return TilCapability.State.UNVERIFIED;
1 ✔
397
        }
398
        if (status >= HttpStatus.OK.getCode() && status < HttpStatus.MULTIPLE_CHOICES.getCode()
1 ✔
399
                || status >= HttpStatus.BAD_REQUEST.getCode()) {
1 ✔
400
            return TilCapability.State.TOO_OLD;
1 ✔
401
        }
NEW
402
        return TilCapability.State.UNVERIFIED;
×
403
    }
404

405
    private static boolean mentions(HttpClientResponseException e, String message) {
406
        return Stream.of(
1 ✔
407
                        body(e, String.class),
1 ✔
408
                        body(e, ProblemDetailsVO.class).map(ProblemDetailsVO::getDetail),
1 ✔
409
                        Optional.ofNullable(e.getMessage()))
1 ✔
410
                .flatMap(Optional::stream)
1 ✔
411
                .anyMatch(text -> text.contains(message));
1 ✔
412
    }
413

414
    private static <T> Optional<T> body(HttpClientResponseException e, Class<T> type) {
415
        try {
416
            return e.getResponse().getBody(type);
1 ✔
NEW
417
        } catch (RuntimeException conversionFailure) {
×
NEW
418
            return Optional.empty();
×
419
        }
420
    }
421

422
    private static String describe(String scope, @Nullable ScopeTypeVO type) {
423
        return type == null ? scope : "%s (%s)".formatted(scope, type.getValue());
1 ✔
424
    }
425

426
    private record Page(int number, @Nullable Integer total, List<String> items) {
1 ✔
427

428
        // a short page, or reaching the total, ends the list
429
        boolean hasNext(int pageSize) {
430
            return total != null && items.size() >= pageSize && (long) (number + 1) * pageSize < total;
1 ✔
431
        }
432
    }
433

434
    // only return credentials intended for local
435
    private List<CredentialsVO> filterLocalCredentialsVO(
436
            List<CredentialsConfigResolver.CredentialConfig> credentialsConfig) {
437
        return credentialsConfig.stream()
1 ✔
438
                .filter(credentialConfig -> credentialConfig.contractManagement().isLocal())
1 ✔
439
                .map(CredentialsConfigResolver.CredentialConfig::credentialsVOS)
1 ✔
440
                .flatMap(List::stream)
1 ✔
441
                .distinct()
1 ✔
442
                .toList();
1 ✔
443
    }
444
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc