[java-idp-plugin-vci] 01/01: Allocation review, fix reserving allocation even in fail case. javadoc improvements, code cleaning

Codeberg noreply at shibboleth.net
Wed Nov 18 14:41:29 UTC 2026


This is an automated email from the git hooks/post-receive script.

codeberg pushed a commit to branch dev/REVASSIGN
in repository java-idp-plugin-vci.

View the commit online:
https://codeberg.org/Shibboleth/java-idp-plugin-vci/commit/da78d5684ab7baf9c1625f0c205af461698ce33a

commit da78d5684ab7baf9c1625f0c205af461698ce33a
Author: Janne Lauros <janne.lauros at csc.fi>
AuthorDate: Wed Nov 18 16:40:49 2026 +0200

    Allocation review, fix reserving allocation even in fail case. javadoc improvements, code cleaning
---
 .../openidvci/statuslist/StatusListIssuerTag.java  |  15 +-
 .../statuslist/context/StatusListContext.java      |  23 +++
 .../logic/CredentialCountLookupFunction.java       |   3 -
 .../logic/CredentialDetailsLookupFunction.java     |   7 -
 .../logic/CredentialExpirationLookupFunction.java  |   3 -
 .../logic/StatusListInclusionPredicate.java        |   4 -
 .../logic/StatusListIssuerTagLookupFunction.java   |  11 +-
 .../statuslist/profile/impl/AllocateIndex.java     |  32 ++--
 .../statuslist/profile/impl/AssignIndex.java       |  27 ++-
 .../storage/StatusListAssignmentStore.java         |  38 ++---
 .../oauth/status-list/assign/assign-beans.xml      |   4 -
 .../flows/oauth/status-list/assign/assign-flow.xml |  15 +-
 .../openid/vci/credentials/credentials-flow.xml    |  14 +-
 .../logic/CredentialCountLookupFunctionTest.java   |  90 ++++++++++
 .../logic/CredentialDetailsLookupFunctionTest.java |  84 +++++++++
 .../CredentialExpirationLookupFunctionTest.java    |  65 +++++++
 .../StatusListIssuerTagLookupFunctionTest.java     |  86 ++++++++++
 .../statuslist/profile/impl/AllocateIndexTest.java |  16 ++
 .../statuslist/profile/impl/AssignIndexTest.java   | 190 +++++++++++++++++++++
 .../storage/StatusListAssignmentStoreTest.java     |  35 ++++
 20 files changed, 655 insertions(+), 107 deletions(-)

diff --git a/openid-vci-api/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/StatusListIssuerTag.java b/openid-vci-api/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/StatusListIssuerTag.java
index f244eee..f1ebcc4 100644
--- a/openid-vci-api/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/StatusListIssuerTag.java
+++ b/openid-vci-api/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/StatusListIssuerTag.java
@@ -20,12 +20,7 @@ import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
 
 /**
- * Tag naming the issuer a Status List Token is published under, as it travels
- * in the url of a status list.
- *
- * Storage is keyed by the bucket alone, so the tag is a runtime matter only and
- * every credential of a month shares one list. A url with no tag names no
- * issuer.
+ * Issuer tag a Status List Token is published under, in the url of a status list.
  */
 public final class StatusListIssuerTag {
 
@@ -43,7 +38,7 @@ public final class StatusListIssuerTag {
     @Nonnull
     public static final String DID_WEB = "did-web";
 
-    /** Tag of a list handed out under a did:jwk, followed by the key it names. */
+    /** Tag of a list handed out under a did:jwk, followed by the thumbprint of its key. */
     @Nonnull
     public static final String DID_JWK = "did-jwk";
 
@@ -58,7 +53,7 @@ public final class StatusListIssuerTag {
     /**
      * Build the tag of a did:jwk issuer.
      *
-     * @param thumbprint thumbprint of the key the identifier names
+     * @param thumbprint thumbprint of the key of the identifier
      * @return the tag
      */
     @Nonnull
@@ -113,10 +108,10 @@ public final class StatusListIssuerTag {
     }
 
     /**
-     * Get the thumbprint a did:jwk tag names.
+     * Get the thumbprint in a did:jwk tag.
      *
      * @param tag tag to read
-     * @return the thumbprint, or null when the tag names no key
+     * @return the thumbprint, or null when the tag carries no key
      */
     @Nullable
     public static String thumbprintOf(@Nullable final String tag) {
diff --git a/openid-vci-api/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/context/StatusListContext.java b/openid-vci-api/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/context/StatusListContext.java
index 2b229dd..bdca52a 100644
--- a/openid-vci-api/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/context/StatusListContext.java
+++ b/openid-vci-api/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/context/StatusListContext.java
@@ -34,6 +34,10 @@ public class StatusListContext extends BaseContext {
     @Nullable
     private String statusListUri;
 
+    /** Bucket the allocated indices belong to. */
+    @Nullable
+    private String bucketId;
+
     /** Allocated status list indices, one per credential. */
     @Nullable
     private List<Long> indices;
@@ -57,6 +61,25 @@ public class StatusListContext extends BaseContext {
         statusListUri = uri;
     }
 
+    /**
+     * Get bucket the allocated indices belong to.
+     *
+     * @return Bucket the allocated indices belong to
+     */
+    @Nullable
+    public String getBucketId() {
+        return bucketId;
+    }
+
+    /**
+     * Set bucket the allocated indices belong to.
+     *
+     * @param id Bucket the allocated indices belong to
+     */
+    public void setBucketId(@Nullable final String id) {
+        bucketId = id;
+    }
+
     /**
      * Get allocated status list indices, one per credential.
      *
diff --git a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/logic/CredentialCountLookupFunction.java b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/logic/CredentialCountLookupFunction.java
index fe192b9..8387e40 100644
--- a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/logic/CredentialCountLookupFunction.java
+++ b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/logic/CredentialCountLookupFunction.java
@@ -30,9 +30,6 @@ import com.nimbusds.jwt.SignedJWT;
 /**
  * Supplies the number of credentials a request will produce, being one per
  * validated proof or attested key in {@link CredentialsContext}.
- *
- * A request without proofs gives one credential without key binding, so the
- * count is one.
  */
 public class CredentialCountLookupFunction implements Function<ProfileRequestContext, Integer> {
 
diff --git a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/logic/CredentialDetailsLookupFunction.java b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/logic/CredentialDetailsLookupFunction.java
index 8c735b9..b882c7c 100644
--- a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/logic/CredentialDetailsLookupFunction.java
+++ b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/logic/CredentialDetailsLookupFunction.java
@@ -30,13 +30,6 @@ import org.opensaml.profile.context.ProfileRequestContext;
 
 /**
  * Describes an issued credential for the record of the status list slots it took.
- *
- * This is all that OpenID VCI does for recording an assignment. The status list side
- * knows nothing about credentials.
- *
- * Claims are reported by path with their values, a claim of a nested object as
- * 'address.locality'. Values are taken from what was requested to be issued. The
- * credential itself has only digests of them.
  */
 public class CredentialDetailsLookupFunction implements Function<ProfileRequestContext, Map<String, Object>> {
 
diff --git a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/logic/CredentialExpirationLookupFunction.java b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/logic/CredentialExpirationLookupFunction.java
index 8205afc..6b3632c 100644
--- a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/logic/CredentialExpirationLookupFunction.java
+++ b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/logic/CredentialExpirationLookupFunction.java
@@ -27,9 +27,6 @@ import org.opensaml.profile.context.ProfileRequestContext;
 /**
  * Supplies the expiration shared by the credentials of a request, as resolved
  * into {@link CredentialsContext}.
- *
- * Returns null if no expiration has been resolved. The caller decides if that
- * is an error.
  */
 public class CredentialExpirationLookupFunction implements Function<ProfileRequestContext, Instant> {
 
diff --git a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/logic/StatusListInclusionPredicate.java b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/logic/StatusListInclusionPredicate.java
index 1feb84e..dd52828 100644
--- a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/logic/StatusListInclusionPredicate.java
+++ b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/logic/StatusListInclusionPredicate.java
@@ -28,10 +28,6 @@ import org.opensaml.profile.context.ProfileRequestContext;
 /**
  * Whether the credentials of this request take a Status List slot, as the
  * 'status_list' member of the Credential Configuration in issue states it.
- *
- * Conditions the actions that allocate and record a slot. Set the default to
- * false to make the Status List something each Credential Configuration opts
- * into.
  */
 public class StatusListInclusionPredicate implements Predicate<ProfileRequestContext> {
 
diff --git a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/logic/StatusListIssuerTagLookupFunction.java b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/logic/StatusListIssuerTagLookupFunction.java
index 4cc19d7..9b082fd 100644
--- a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/logic/StatusListIssuerTagLookupFunction.java
+++ b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/profile/logic/StatusListIssuerTagLookupFunction.java
@@ -39,12 +39,8 @@ import net.shibboleth.shared.logic.Constraint;
 import net.shibboleth.shared.primitive.LoggerFactory;
 
 /**
- * Tag naming the Credential Issuer identifier a credential is issued under, for
- * the url of the status list it takes a slot of.
- *
- * A did:web or url identifier is the same for every credential of this
- * deployment and takes a static tag. A did:jwk identifier names a key, so its
- * tag carries the thumbprint of that key.
+ * Issuer tag of the status list url, from the Credential Issuer identifier of the
+ * credential in issue.
  */
 public class StatusListIssuerTagLookupFunction implements Function<ProfileRequestContext, String> {
 
@@ -109,7 +105,8 @@ public class StatusListIssuerTagLookupFunction implements Function<ProfileReques
 
         final String thumbprint = thumbprint(profileRequestContext);
         if (thumbprint == null) {
-            log.error("Unable to name the key of issuer '{}', status list url carries no tag", issuer);
+            log.error("Unable to take a thumbprint of the signing key of issuer '{}', status list url carries no tag",
+                    issuer);
             return null;
         }
         return StatusListIssuerTag.didJwk(thumbprint);
diff --git a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/profile/impl/AllocateIndex.java b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/profile/impl/AllocateIndex.java
index 8404b01..011e821 100644
--- a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/profile/impl/AllocateIndex.java
+++ b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/profile/impl/AllocateIndex.java
@@ -46,15 +46,12 @@ import net.shibboleth.shared.primitive.LoggerFactory;
  * Action that allocates status list slots via {@link StatusListIndexAllocator}
  * and populates a {@link StatusListContext} on the outbound
  * {@link MessageContext}.
- *
- * Bucket is chosen from the expiration of the credentials, list always outlives
- * the credentials in it.
  */
 public class AllocateIndex extends AbstractProfileAction {
 
     /** Class logger. */
     @Nonnull
-    private Logger log = LoggerFactory.getLogger(AllocateIndex.class);
+    private final Logger log = LoggerFactory.getLogger(AllocateIndex.class);
 
     /** Allocator for status list slots. */
     @NonnullAfterInit
@@ -82,10 +79,7 @@ public class AllocateIndex extends AbstractProfileAction {
     @NonnullAfterInit
     private String issuer;
 
-    /**
-     * Strategy used to resolve the tag naming the issuer of the credential in
-     * issue.
-     */
+    /** Strategy used to resolve the issuer tag of the status list url. */
     @Nullable
     private Function<ProfileRequestContext, String> issuerTagLookupStrategy;
 
@@ -147,6 +141,16 @@ public class AllocateIndex extends AbstractProfileAction {
         issuer = Constraint.isNotNull(url, "Issuer cannot be null");
     }
 
+    /**
+     * Set the strategy used to resolve the issuer tag of the status list url.
+     *
+     * @param strategy lookup strategy, or null for urls with no tag
+     */
+    public void setIssuerTagLookupStrategy(@Nullable final Function<ProfileRequestContext, String> strategy) {
+        checkSetterPreconditions();
+        issuerTagLookupStrategy = strategy;
+    }
+
     /** {@inheritDoc} */
     @Override
     protected void doInitialize() throws ComponentInitializationException {
@@ -170,17 +174,6 @@ public class AllocateIndex extends AbstractProfileAction {
         }
     }
 
-    /**
-     * Set the strategy used to resolve the tag naming the issuer of the credential
-     * in issue. The tag travels in the status list url and nowhere else.
-     *
-     * @param strategy lookup strategy, or null to publish urls with no tag
-     */
-    public void setIssuerTagLookupStrategy(@Nullable final Function<ProfileRequestContext, String> strategy) {
-        checkSetterPreconditions();
-        issuerTagLookupStrategy = strategy;
-    }
-
     /** {@inheritDoc} */
     @Override
     protected boolean doPreExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
@@ -237,6 +230,7 @@ public class AllocateIndex extends AbstractProfileAction {
 
         final StatusListContext ctx = outbound.ensureSubcontext(StatusListContext.class);
         ctx.setStatusListUri(statusListUri);
+        ctx.setBucketId(bucket.id());
         ctx.setIndices(indices);
 
         log.debug("{} Allocated {} status list slot(s) {} from bucket {} (retirable after {}) at uri {}",
diff --git a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/profile/impl/AssignIndex.java b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/profile/impl/AssignIndex.java
index 3c45eb8..6ecb864 100644
--- a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/profile/impl/AssignIndex.java
+++ b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/profile/impl/AssignIndex.java
@@ -26,12 +26,10 @@ import javax.annotation.Nullable;
 
 import net.shibboleth.idp.profile.AbstractProfileAction;
 import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
-import net.shibboleth.shared.annotation.constraint.NonnullBeforeExec;
 import net.shibboleth.shared.component.ComponentInitializationException;
 import net.shibboleth.shared.logic.Constraint;
 import net.shibboleth.shared.primitive.LoggerFactory;
 
-import org.geant.shibboleth.plugin.openidvci.statuslist.MonthlyBucketStrategy;
 import org.geant.shibboleth.plugin.openidvci.statuslist.context.StatusListContext;
 import org.geant.shibboleth.plugin.openidvci.statuslist.storage.StatusListAssignment;
 import org.geant.shibboleth.plugin.openidvci.statuslist.storage.StatusListAssignmentStore;
@@ -43,32 +41,30 @@ import org.slf4j.Logger;
 /**
  * Action that records the slots allocated by {@link AllocateIndex}, to be collected
  * by a party outside the IdP.
- *
- * Failing to write the record fails the issuance. 
  */
 public class AssignIndex extends AbstractProfileAction {
 
     /** Class logger. */
     @Nonnull
-    private Logger log = LoggerFactory.getLogger(AssignIndex.class);
+    private final Logger log = LoggerFactory.getLogger(AssignIndex.class);
 
     /** Store handing records to a collector. */
     @NonnullAfterInit
     private StatusListAssignmentStore statusListAssignmentStore;
 
-    /** Strategy used to obtain the expiration of what took the slots. */
+    /** Strategy used to obtain the expiration shared by the credentials issued. */
     @NonnullAfterInit
     private Function<ProfileRequestContext, Instant> expirationLookupStrategy;
 
-    /** Strategy used to obtain a description of what took the slots. */
+    /** Strategy used to obtain a description of the credentials issued. */
     @NonnullAfterInit
     private Function<ProfileRequestContext, Map<String, Object>> detailsLookupStrategy;
 
     /** Status list context. */
-    @NonnullBeforeExec
+    @Nullable
     private StatusListContext statusListContext;
 
-    /** Expiration of what took the slots. */
+    /** Expiration shared by the credentials issued. */
     @Nullable
     private Instant expiration;
 
@@ -83,7 +79,8 @@ public class AssignIndex extends AbstractProfileAction {
     }
 
     /**
-     * Set the strategy used to obtain the expiration of what took slots.
+     * Set the strategy used to obtain the expiration shared by the credentials
+     * issued.
      *
      * @param strategy lookup strategy
      */
@@ -93,7 +90,7 @@ public class AssignIndex extends AbstractProfileAction {
     }
 
     /**
-     * Set the strategy used to obtain a description of what took slots.
+     * Set the strategy used to obtain a description of the credentials issued.
      *
      * @param strategy lookup strategy
      */
@@ -129,7 +126,8 @@ public class AssignIndex extends AbstractProfileAction {
             statusListContext = profileRequestContext.getOutboundMessageContext()
                     .getSubcontext(StatusListContext.class);
         }
-        if (statusListContext == null || statusListContext.getIndices() == null) {
+        if (statusListContext == null || statusListContext.getIndices() == null
+                || statusListContext.getBucketId() == null) {
             log.error("{} No allocated slots to record", getLogPrefix());
             ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_PROFILE_CTX);
             return false;
@@ -137,7 +135,7 @@ public class AssignIndex extends AbstractProfileAction {
 
         expiration = expirationLookupStrategy.apply(profileRequestContext);
         if (expiration == null) {
-            log.error("{} Unable to determine the expiration of what took the slots", getLogPrefix());
+            log.error("{} Unable to determine the expiration of the credentials issued", getLogPrefix());
             ActionSupport.buildEvent(profileRequestContext, EventIds.INVALID_PROFILE_CTX);
             return false;
         }
@@ -149,9 +147,10 @@ public class AssignIndex extends AbstractProfileAction {
     @Override
     protected void doExecute(@Nonnull final ProfileRequestContext profileRequestContext) {
         assert expiration != null;
+        assert statusListContext != null;
 
         final StatusListAssignment record = new StatusListAssignment();
-        record.setId(new MonthlyBucketStrategy().apply(expiration).id());
+        record.setId(statusListContext.getBucketId());
         record.setIndices(statusListContext.getIndices());
         record.setExpires(expiration.getEpochSecond());
         record.setDetails(detailsLookupStrategy.apply(profileRequestContext));
diff --git a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/storage/StatusListAssignmentStore.java b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/storage/StatusListAssignmentStore.java
index 9b21954..1774902 100644
--- a/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/storage/StatusListAssignmentStore.java
+++ b/openid-vci-impl/src/main/java/org/geant/shibboleth/plugin/openidvci/statuslist/storage/StatusListAssignmentStore.java
@@ -25,6 +25,7 @@ import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 
 import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
 
 import net.shibboleth.shared.annotation.constraint.NonnullAfterInit;
 import net.shibboleth.shared.annotation.constraint.NotEmpty;
@@ -45,11 +46,6 @@ import com.fasterxml.jackson.core.JsonProcessingException;
 /**
  * Store handing {@link StatusListAssignment} records to a collector outside the
  * IdP, backed by Shibboleth {@link StorageService}.
- *
- * Records are numbered each taking the first free position from a sequence stored
- * with them. The sequence moves past a position only once its record is stored, so
- * every position below it holds a record until the record expires. A collector
- * reads page from a position it remembers and continues from the end of the page.
  */
 @ThreadSafeAfterInit
 public class StatusListAssignmentStore extends AbstractIdentifiableInitializableComponent {
@@ -85,6 +81,7 @@ public class StatusListAssignmentStore extends AbstractIdentifiableInitializable
     private Duration retention = Duration.ofDays(7);
 
     /** Backing storage for the records. */
+    @NonnullAfterInit
     private StorageService storage;
 
     /**
@@ -125,9 +122,6 @@ public class StatusListAssignmentStore extends AbstractIdentifiableInitializable
     /**
      * Set how long a record waits to be collected.
      *
-     * Long enough that a collector being down does not lose the possibility to
-     * revoke what was issued in the meantime.
-     *
      * @param recordRetention positive retention
      */
     public void setRetention(@Nonnull final Duration recordRetention) {
@@ -151,9 +145,6 @@ public class StatusListAssignmentStore extends AbstractIdentifiableInitializable
     /**
      * Store a record of an assignment.
      *
-     * The record takes the first free position from the sequence on, and the sequence
-     * then moves past it. One record is stored at a time within this node.
-     *
      * @param record record to store
      * @throws IOException if the record cannot be serialized or stored, or if
      *                     contention could not be resolved within
@@ -209,10 +200,6 @@ public class StatusListAssignmentStore extends AbstractIdentifiableInitializable
     /**
      * Read a page of records.
      *
-     * Positions are read one by one and an empty position is skipped, an expired
-     * record leaves a gap. The number of positions read is bounded, so a collector
-     * that is far behind gets one page at a time.
-     *
      * @param from  position to read from
      * @param limit most records to return
      * @return the records read, and where to continue
@@ -255,7 +242,22 @@ public class StatusListAssignmentStore extends AbstractIdentifiableInitializable
     private long currentSequence() throws IOException {
         final StorageRecord<String> record = storage.read(CONTEXT, KEY_SEQUENCE);
 
-        return record == null ? 0L : Long.parseLong(record.getValue());
+        return record == null ? 0L : parseSequence(record.getValue());
+    }
+
+    /**
+     * Parse a stored sequence.
+     *
+     * @param value stored value
+     * @return the sequence
+     * @throws IOException if the stored value is not a number
+     */
+    private long parseSequence(@Nullable final String value) throws IOException {
+        try {
+            return Long.parseLong(value);
+        } catch (final NumberFormatException e) {
+            throw new IOException("Record sequence is not a number", e);
+        }
     }
 
     /**
@@ -268,15 +270,13 @@ public class StatusListAssignmentStore extends AbstractIdentifiableInitializable
         for (int attempt = 0; attempt < MAX_RETRIES; attempt++) {
             final StorageRecord<String> current = storage.read(CONTEXT, KEY_SEQUENCE);
             if (current == null) {
-                // The sequence outlives every record it numbers, so it is kept without
-                // expiration.
                 if (storage.create(CONTEXT, KEY_SEQUENCE, Long.toString(next), null)) {
                     return;
                 }
                 continue;
             }
             final long version = current.getVersion();
-            if (Long.parseLong(current.getValue()) >= next) {
+            if (parseSequence(current.getValue()) >= next) {
                 return;
             }
             try {
diff --git a/openid-vci-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/oauth/status-list/assign/assign-beans.xml b/openid-vci-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/oauth/status-list/assign/assign-beans.xml
index c95a919..53bc345 100644
--- a/openid-vci-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/oauth/status-list/assign/assign-beans.xml
+++ b/openid-vci-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/oauth/status-list/assign/assign-beans.xml
@@ -27,10 +27,6 @@
     <property name="indexCountLookupStrategy">
       <bean class="org.geant.shibboleth.plugin.openidvci.profile.logic.CredentialCountLookupFunction" />
     </property>
-    <!--
-    Names the Credential Issuer identifier of the credential in the status list url, so the
-    endpoint answers under it. Storage is keyed by the bucket alone, the tag is url only.
-    -->
     <property name="issuerTagLookupStrategy">
       <bean class="org.geant.shibboleth.plugin.openidvci.profile.logic.StatusListIssuerTagLookupFunction"
             p:issuerLookupStrategy-ref="openidvci.IssuerLookupStrategy" />
diff --git a/openid-vci-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/oauth/status-list/assign/assign-flow.xml b/openid-vci-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/oauth/status-list/assign/assign-flow.xml
index 316de88..36abdfa 100644
--- a/openid-vci-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/oauth/status-list/assign/assign-flow.xml
+++ b/openid-vci-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/oauth/status-list/assign/assign-flow.xml
@@ -4,21 +4,16 @@
     xsi:schemaLocation="http://www.springframework.org/schema/webflow http://www.springframework.org/schema/webflow/spring-webflow.xsd"
     abstract="true">
 
-    <!-- 1. creates status list context if status list is used --> 
-    <!-- 2. Allocates index from storage --> 
-    <!-- 3. Sets allocated index index to status list context --> 
-    <action-state id="AllocateStatusListIndex">
+    <action-state id="DoStatusListAllocation">
         <evaluate expression="AllocateIndex" />
         <evaluate expression="'proceed'" />
-        <transition on="proceed" to="ResumeAfterAllocateStatusListIndex" />
+        <transition on="proceed" to="ResumeAfterDoStatusListAllocation" />
     </action-state>
-    
-    <!-- 1. Reads  index and credential metadata (string) from status list context--> 
-    <!-- 2. Stores index and credential metadata to storage or uses remote API --> 
-    <action-state id="AssignStatusListIndex">
+
+    <action-state id="DoStatusListAssignment">
         <evaluate expression="AssignIndex" />
         <evaluate expression="'proceed'" />
-        <transition on="proceed" to="ResumeAfterAssignStatusListIndex" />
+        <transition on="proceed" to="ResumeAfterDoStatusListAssignment" />
     </action-state>
 
     <bean-import resource="classpath:/META-INF/net/shibboleth/idp/flows/oauth/status-list/assign/assign-beans.xml" />
diff --git a/openid-vci-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/openid/vci/credentials/credentials-flow.xml b/openid-vci-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/openid/vci/credentials/credentials-flow.xml
index 679c958..e6b328f 100644
--- a/openid-vci-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/openid/vci/credentials/credentials-flow.xml
+++ b/openid-vci-impl/src/main/resources/META-INF/net/shibboleth/idp/flows/openid/vci/credentials/credentials-flow.xml
@@ -36,15 +36,10 @@
     <!-- Fixes iat/exp for all credentials of this request. The status list bucket comes from it. -->
     <evaluate expression="ResolveCredentialLifetime" />
     <evaluate expression="'proceed'" />
-    <transition on="proceed" to="AllocateStatusListIndex" />
+    <transition on="proceed" to="DoStatusListAllocation" />
   </action-state>
 
-  <action-state id="ResumeAfterAllocateStatusListIndex">
-    <evaluate expression="'proceed'" />
-    <transition on="proceed" to="AssignStatusListIndex" />
-  </action-state>
-
-  <action-state id="ResumeAfterAssignStatusListIndex">
+  <action-state id="ResumeAfterDoStatusListAllocation">
     <evaluate expression="'proceed'" />
     <transition on="proceed" to="BuildResponse" />
   </action-state>
@@ -57,6 +52,11 @@
     <evaluate expression="AddMobileSecurityObjectShell" />
     <evaluate expression="AddClaimsToMobileSecurityObject" />
     <evaluate expression="SignMobileSecurityObject" />
+    <evaluate expression="'proceed'" />
+    <transition on="proceed" to="DoStatusListAssignment" />
+  </action-state>
+
+  <action-state id="ResumeAfterDoStatusListAssignment">
     <evaluate expression="'proceed'" />
     <transition on="proceed" to="BuildResponseMessage" />
   </action-state>
diff --git a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/logic/CredentialCountLookupFunctionTest.java b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/logic/CredentialCountLookupFunctionTest.java
new file mode 100644
index 0000000..a2410b0
--- /dev/null
+++ b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/logic/CredentialCountLookupFunctionTest.java
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2025, GÉANT
+ *
+ * Licensed under the Apache License, Version 2.0 (the “License”); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at
+ *
+ *    http://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.
+ */
+
+package org.geant.shibboleth.plugin.openidvci.profile.logic;
+
+import java.util.List;
+
+import org.geant.shibboleth.plugin.openidvci.messaging.context.CredentialsContext;
+import org.opensaml.messaging.context.MessageContext;
+import org.opensaml.profile.context.ProfileRequestContext;
+import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.nimbusds.jose.JOSEException;
+import com.nimbusds.jose.JWSAlgorithm;
+import com.nimbusds.jose.JWSHeader;
+import com.nimbusds.jose.jwk.Curve;
+import com.nimbusds.jose.jwk.JWK;
+import com.nimbusds.jose.jwk.gen.ECKeyGenerator;
+import com.nimbusds.jwt.JWTClaimsSet;
+import com.nimbusds.jwt.SignedJWT;
+
+/**
+ * Tests for {@link CredentialCountLookupFunction}.
+ */
+public class CredentialCountLookupFunctionTest {
+
+    private final CredentialCountLookupFunction lookup = new CredentialCountLookupFunction();
+
+    private ProfileRequestContext prc;
+
+    private CredentialsContext ctx;
+
+    @BeforeMethod
+    public void setUp() {
+        prc = new ProfileRequestContext();
+        prc.setInboundMessageContext(new MessageContext());
+        ctx = prc.getInboundMessageContext().ensureSubcontext(CredentialsContext.class);
+    }
+
+    private static SignedJWT proof() {
+        return new SignedJWT(new JWSHeader(JWSAlgorithm.ES256), new JWTClaimsSet.Builder().build());
+    }
+
+    private static JWK key() throws JOSEException {
+        return new ECKeyGenerator(Curve.P_256).generate();
+    }
+
+    @Test
+    public void testOnePerProof() {
+        ctx.setProofs(List.of(proof(), proof(), proof()));
+        Assert.assertEquals(lookup.apply(prc), Integer.valueOf(3));
+    }
+
+    @Test
+    public void testAttestedKeysOverProofs() throws JOSEException {
+        ctx.setProofs(List.of(proof()));
+        ctx.setAttestedKeys(List.of(key(), key()));
+        Assert.assertEquals(lookup.apply(prc), Integer.valueOf(2));
+    }
+
+    @Test
+    public void testNoProofs() {
+        Assert.assertEquals(lookup.apply(prc), Integer.valueOf(1));
+        ctx.setProofs(List.of());
+        ctx.setAttestedKeys(List.of());
+        Assert.assertEquals(lookup.apply(prc), Integer.valueOf(1));
+    }
+
+    @Test
+    public void testNoContexts() {
+        Assert.assertEquals(lookup.apply(new ProfileRequestContext()), Integer.valueOf(1));
+        Assert.assertEquals(lookup.apply(null), Integer.valueOf(1));
+    }
+
+}
diff --git a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/logic/CredentialDetailsLookupFunctionTest.java b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/logic/CredentialDetailsLookupFunctionTest.java
new file mode 100644
index 0000000..c6bf966
--- /dev/null
+++ b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/logic/CredentialDetailsLookupFunctionTest.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2025, GÉANT
+ *
+ * Licensed under the Apache License, Version 2.0 (the “License”); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at
+ *
+ *    http://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.
+ */
+
+package org.geant.shibboleth.plugin.openidvci.profile.logic;
+
+import java.util.List;
+import java.util.Map;
+
+import org.geant.shibboleth.plugin.openidvci.credential.CredentialConfiguration;
+import org.geant.shibboleth.plugin.openidvci.messaging.context.CredentialsContext;
+import org.geant.shibboleth.plugin.openidvci.messaging.impl.CredentialOfferRequestedClaim;
+import org.geant.shibboleth.plugin.openidvci.messaging.impl.CredentialOfferRequestedCredential;
+import org.opensaml.messaging.context.MessageContext;
+import org.opensaml.profile.context.ProfileRequestContext;
+import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+
+/**
+ * Tests for {@link CredentialDetailsLookupFunction}.
+ */
+public class CredentialDetailsLookupFunctionTest {
+
+    private final CredentialDetailsLookupFunction lookup = new CredentialDetailsLookupFunction();
+
+    private ProfileRequestContext prc;
+
+    private CredentialsContext ctx;
+
+    @BeforeMethod
+    public void setUp() throws JsonProcessingException {
+        prc = new ProfileRequestContext();
+        prc.setInboundMessageContext(new MessageContext());
+        ctx = prc.getInboundMessageContext().ensureSubcontext(CredentialsContext.class);
+        ctx.setCredentialConfigurationId("diploma");
+        ctx.setCredentialConfiguration(CredentialConfiguration.parse("{\"format\":\"dc+sd-jwt\",\"vct\":\"Diploma\"}"));
+    }
+
+    @Test
+    public void testDetails() {
+        ctx.setDatasetId("dataset-1");
+        ctx.setCredentialContent(new CredentialOfferRequestedCredential(List.of(
+                CredentialOfferRequestedClaim.of(List.of("given_name"), "Alice"),
+                CredentialOfferRequestedClaim.of(List.of("address", "locality"), "Espoo"))));
+
+        final Map<String, Object> details = lookup.apply(prc);
+        Assert.assertEquals(details.get("credential_configuration_id"), "diploma");
+        Assert.assertEquals(details.get("dataset_id"), "dataset-1");
+        Assert.assertEquals(details.get("format"), "dc+sd-jwt");
+        Assert.assertEquals(details.get("claims"), Map.of("given_name", "Alice", "address.locality", "Espoo"));
+    }
+
+    @Test
+    public void testNoDatasetNoRequestedCredential() {
+        final Map<String, Object> details = lookup.apply(prc);
+        Assert.assertEquals(details.get("credential_configuration_id"), "diploma");
+        Assert.assertFalse(details.containsKey("dataset_id"));
+        Assert.assertEquals(details.get("claims"), Map.of());
+    }
+
+    @Test
+    public void testNoContexts() {
+        Assert.assertTrue(lookup.apply(new ProfileRequestContext()).isEmpty());
+        Assert.assertTrue(lookup.apply(null).isEmpty());
+        prc.getInboundMessageContext().removeSubcontext(CredentialsContext.class);
+        Assert.assertTrue(lookup.apply(prc).isEmpty());
+    }
+
+}
diff --git a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/logic/CredentialExpirationLookupFunctionTest.java b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/logic/CredentialExpirationLookupFunctionTest.java
new file mode 100644
index 0000000..dcc42f3
--- /dev/null
+++ b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/logic/CredentialExpirationLookupFunctionTest.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2025, GÉANT
+ *
+ * Licensed under the Apache License, Version 2.0 (the “License”); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at
+ *
+ *    http://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.
+ */
+
+package org.geant.shibboleth.plugin.openidvci.profile.logic;
+
+import java.time.Instant;
+
+import org.geant.shibboleth.plugin.openidvci.messaging.context.CredentialsContext;
+import org.opensaml.messaging.context.MessageContext;
+import org.opensaml.profile.context.ProfileRequestContext;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+/**
+ * Tests for {@link CredentialExpirationLookupFunction}.
+ */
+public class CredentialExpirationLookupFunctionTest {
+
+    private static final Instant EXPIRATION = Instant.parse("2027-02-18T12:00:00Z");
+
+    private final CredentialExpirationLookupFunction lookup = new CredentialExpirationLookupFunction();
+
+    @Test
+    public void testExpirationResolved() {
+        final ProfileRequestContext prc = new ProfileRequestContext();
+        prc.setInboundMessageContext(new MessageContext());
+        prc.getInboundMessageContext().ensureSubcontext(CredentialsContext.class).setExpiresAt(EXPIRATION);
+        Assert.assertEquals(lookup.apply(prc), EXPIRATION);
+    }
+
+    @Test
+    public void testExpirationNotResolved() {
+        final ProfileRequestContext prc = new ProfileRequestContext();
+        prc.setInboundMessageContext(new MessageContext());
+        prc.getInboundMessageContext().ensureSubcontext(CredentialsContext.class);
+        Assert.assertNull(lookup.apply(prc));
+    }
+
+    @Test
+    public void testNoCredentialsContext() {
+        final ProfileRequestContext prc = new ProfileRequestContext();
+        prc.setInboundMessageContext(new MessageContext());
+        Assert.assertNull(lookup.apply(prc));
+    }
+
+    @Test
+    public void testNoContexts() {
+        Assert.assertNull(lookup.apply(new ProfileRequestContext()));
+        Assert.assertNull(lookup.apply(null));
+    }
+
+}
diff --git a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/logic/StatusListIssuerTagLookupFunctionTest.java b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/logic/StatusListIssuerTagLookupFunctionTest.java
new file mode 100644
index 0000000..19fc61a
--- /dev/null
+++ b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/profile/logic/StatusListIssuerTagLookupFunctionTest.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2025, GÉANT
+ *
+ * Licensed under the Apache License, Version 2.0 (the “License”); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at
+ *
+ *    http://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.
+ */
+
+package org.geant.shibboleth.plugin.openidvci.profile.logic;
+
+import org.geant.shibboleth.plugin.openidvci.statuslist.StatusListIssuerTag;
+import org.opensaml.messaging.context.MessageContext;
+import org.opensaml.profile.context.ProfileRequestContext;
+import org.opensaml.security.credential.BasicCredential;
+import org.testng.Assert;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.nimbusds.jose.JOSEException;
+import com.nimbusds.jose.jwk.Curve;
+import com.nimbusds.jose.jwk.ECKey;
+import com.nimbusds.jose.jwk.gen.ECKeyGenerator;
+
+import net.shibboleth.oidc.security.jose.SignatureSigningParameters;
+import net.shibboleth.oidc.security.jose.context.SecurityParametersContext;
+
+/**
+ * Tests for {@link StatusListIssuerTagLookupFunction}.
+ */
+public class StatusListIssuerTagLookupFunctionTest {
+
+    private ProfileRequestContext prc;
+
+    @BeforeMethod
+    public void setUp() {
+        prc = new ProfileRequestContext();
+        prc.setOutboundMessageContext(new MessageContext());
+    }
+
+    private StatusListIssuerTagLookupFunction lookupFor(final String issuer) {
+        final StatusListIssuerTagLookupFunction lookup = new StatusListIssuerTagLookupFunction();
+        lookup.setIssuerLookupStrategy(input -> issuer);
+        return lookup;
+    }
+
+    @Test
+    public void testDidWeb() {
+        Assert.assertEquals(lookupFor("did:web:issuer.example.org").apply(prc), StatusListIssuerTag.DID_WEB);
+    }
+
+    @Test
+    public void testUrl() {
+        Assert.assertEquals(lookupFor("https://issuer.example.org").apply(prc), StatusListIssuerTag.URL);
+    }
+
+    @Test
+    public void testNoIssuer() {
+        Assert.assertNull(lookupFor(null).apply(prc));
+    }
+
+    @Test
+    public void testDidJwk() throws JOSEException {
+        final ECKey key = new ECKeyGenerator(Curve.P_256).generate();
+        final SignatureSigningParameters params = new SignatureSigningParameters();
+        params.setSigningCredential(new BasicCredential(key.toECPublicKey(), key.toECPrivateKey()));
+        prc.getOutboundMessageContext().ensureSubcontext(SecurityParametersContext.class)
+                .setSignatureSigningParameters(params);
+
+        Assert.assertEquals(lookupFor("did:jwk:eyJrdHkiOiJFQyJ9").apply(prc),
+                StatusListIssuerTag.didJwk(key.toPublicJWK().computeThumbprint().toString()));
+    }
+
+    @Test
+    public void testDidJwkWithoutSigningParameters() {
+        Assert.assertNull(lookupFor("did:jwk:eyJrdHkiOiJFQyJ9").apply(prc));
+    }
+
+}
diff --git a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/statuslist/profile/impl/AllocateIndexTest.java b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/statuslist/profile/impl/AllocateIndexTest.java
index beea030..1ca5b2e 100644
--- a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/statuslist/profile/impl/AllocateIndexTest.java
+++ b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/statuslist/profile/impl/AllocateIndexTest.java
@@ -173,6 +173,7 @@ public class AllocateIndexTest {
         StatusListContext ctx = outboundStatusListContext();
         Assert.assertNotNull(ctx);
         Assert.assertEquals(ctx.getStatusListUri(), EXPECTED_URI);
+        Assert.assertEquals(ctx.getBucketId(), "2027-02");
         Assert.assertEquals(ctx.getIndices().size(), 1);
         Assert.assertNotNull(ctx.getIndex(0));
         Assert.assertNull(ctx.getIndex(1));
@@ -195,6 +196,7 @@ public class AllocateIndexTest {
         ActionTestingSupport.assertProceedEvent(a.execute(requestCtx));
         Assert.assertEquals(outboundStatusListContext().getStatusListUri(),
                 "https://issuer.example.org/idp/profile/oauth/status-list/list?id=2027-03");
+        Assert.assertEquals(outboundStatusListContext().getBucketId(), "2027-03");
     }
 
     @Test
@@ -259,6 +261,20 @@ public class AllocateIndexTest {
         a.initialize();
         ActionTestingSupport.assertProceedEvent(a.execute(requestCtx));
         Assert.assertEquals(outboundStatusListContext().getStatusListUri(), EXPECTED_URI + "~did-jwk:abc");
+        Assert.assertEquals(outboundStatusListContext().getBucketId(), "2027-02");
+    }
+
+    @Test
+    public void testIssuerTagNull() throws ComponentInitializationException {
+        final AllocateIndex a = new AllocateIndex();
+        a.setIssuer(ISSUER);
+        a.setStatusListAllocator(allocator);
+        a.setExpirationLookupStrategy(prc -> EXPIRATION);
+        a.setIndexCountLookupStrategy(prc -> 1);
+        a.setIssuerTagLookupStrategy(prc -> null);
+        a.initialize();
+        ActionTestingSupport.assertProceedEvent(a.execute(requestCtx));
+        Assert.assertEquals(outboundStatusListContext().getStatusListUri(), EXPECTED_URI);
     }
 
     @Test(expectedExceptions = ComponentInitializationException.class)
diff --git a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/statuslist/profile/impl/AssignIndexTest.java b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/statuslist/profile/impl/AssignIndexTest.java
new file mode 100644
index 0000000..30f55c3
--- /dev/null
+++ b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/statuslist/profile/impl/AssignIndexTest.java
@@ -0,0 +1,190 @@
+/*
+ * Copyright (c) 2025, GÉANT
+ *
+ * Licensed under the Apache License, Version 2.0 (the “License”); you may not
+ * use this file except in compliance with the License. You may obtain a copy
+ * of the License at
+ *
+ *    http://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.
+ */
+
+package org.geant.shibboleth.plugin.openidvci.statuslist.profile.impl;
+
+import java.io.IOException;
+import java.time.Instant;
+import java.util.List;
+import java.util.Map;
+
+import org.geant.shibboleth.plugin.openidvci.statuslist.context.StatusListContext;
+import org.geant.shibboleth.plugin.openidvci.statuslist.storage.StatusListAssignment;
+import org.geant.shibboleth.plugin.openidvci.statuslist.storage.StatusListAssignmentStore;
+import org.geant.shibboleth.plugin.openidvci.statuslist.storage.StatusListAssignments;
+import org.opensaml.messaging.context.MessageContext;
+import org.opensaml.profile.action.EventIds;
+import org.opensaml.profile.context.ProfileRequestContext;
+import org.opensaml.storage.impl.MemoryStorageService;
+import org.springframework.webflow.execution.RequestContext;
+import org.testng.Assert;
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import net.shibboleth.idp.profile.context.navigate.WebflowRequestContextProfileRequestContextLookup;
+import net.shibboleth.idp.profile.testing.ActionTestingSupport;
+import net.shibboleth.idp.profile.testing.RequestContextBuilder;
+import net.shibboleth.shared.component.ComponentInitializationException;
+
+/**
+ * Tests for {@link AssignIndex}
+ */
+public class AssignIndexTest {
+
+    private static final Instant EXPIRATION = Instant.parse("2027-02-18T12:00:00Z");
+
+    private static final String BUCKET_ID = "2027-02";
+
+    private static final List<Long> INDICES = List.of(17L, 4242L);
+
+    private static final Map<String, Object> DETAILS = Map.of("format", "dc+sd-jwt");
+
+    protected RequestContext requestCtx;
+
+    protected ProfileRequestContext profileRequestCtx;
+
+    private MemoryStorageService storageService;
+
+    private StatusListAssignmentStore store;
+
+    @BeforeMethod
+    protected void setUp() throws Exception {
+        storageService = new MemoryStorageService();
+        storageService.setId("test");
+        storageService.initialize();
+
+        store = new StatusListAssignmentStore();
+        store.setId("test");
+        store.setStorage(storageService);
+        store.initialize();
+
+        requestCtx = new RequestContextBuilder().buildRequestContext();
+        profileRequestCtx = new WebflowRequestContextProfileRequestContextLookup().apply(requestCtx);
+        profileRequestCtx.setOutboundMessageContext(new MessageContext());
+        final StatusListContext ctx = profileRequestCtx.getOutboundMessageContext()
+                .ensureSubcontext(StatusListContext.class);
+        ctx.setBucketId(BUCKET_ID);
+        ctx.setIndices(INDICES);
+    }
+
+    @AfterMethod
+    protected void tearDown() {
+        store.destroy();
+        store = null;
+        storageService.destroy();
+        storageService = null;
+    }
+
+    private AssignIndex newAction(final StatusListAssignmentStore assignmentStore, final Instant expiration)
+            throws ComponentInitializationException {
+        final AssignIndex a = new AssignIndex();
+        a.setStatusListAssignmentStore(assignmentStore);
+        a.setExpirationLookupStrategy(prc -> expiration);
+        a.setDetailsLookupStrategy(prc -> DETAILS);
+        a.initialize();
+        return a;
+    }
+
+    private StatusListContext outboundStatusListContext() {
+        return profileRequestCtx.getOutboundMessageContext().getSubcontext(StatusListContext.class);
+    }
+
+    @Test
+    public void testSuccess() throws Exception {
+        ActionTestingSupport.assertProceedEvent(newAction(store, EXPIRATION).execute(requestCtx));
+        final StatusListAssignments read = store.read(0, 10);
+        Assert.assertEquals(read.getRecords().size(), 1);
+        final StatusListAssignment record = read.getRecords().get(0);
+        Assert.assertEquals(record.getId(), BUCKET_ID);
+        Assert.assertEquals(record.getIndices(), INDICES);
+        Assert.assertEquals(record.getExpires(), EXPIRATION.getEpochSecond());
+        Assert.assertEquals(record.getDetails(), DETAILS);
+    }
+
+    @Test
+    public void testNoOutboundMessageContext() throws ComponentInitializationException {
+        profileRequestCtx.setOutboundMessageContext(null);
+        ActionTestingSupport.assertEvent(newAction(store, EXPIRATION).execute(requestCtx),
+                EventIds.INVALID_PROFILE_CTX);
+    }
+
+    @Test
+    public void testNoStatusListContext() throws ComponentInitializationException {
+        profileRequestCtx.getOutboundMessageContext().removeSubcontext(StatusListContext.class);
+        ActionTestingSupport.assertEvent(newAction(store, EXPIRATION).execute(requestCtx),
+                EventIds.INVALID_PROFILE_CTX);
+    }
+
+    @Test
+    public void testNoIndices() throws ComponentInitializationException {
+        outboundStatusListContext().setIndices(null);
+        ActionTestingSupport.assertEvent(newAction(store, EXPIRATION).execute(requestCtx),
+                EventIds.INVALID_PROFILE_CTX);
+    }
+
+    @Test
+    public void testNoBucketId() throws ComponentInitializationException {
+        outboundStatusListContext().setBucketId(null);
+        ActionTestingSupport.assertEvent(newAction(store, EXPIRATION).execute(requestCtx),
+                EventIds.INVALID_PROFILE_CTX);
+    }
+
+    @Test
+    public void testNoExpirationAvailable() throws ComponentInitializationException {
+        ActionTestingSupport.assertEvent(newAction(store, null).execute(requestCtx), EventIds.INVALID_PROFILE_CTX);
+    }
+
+    @Test
+    public void testStoreIoError() throws ComponentInitializationException {
+        final StatusListAssignmentStore failing = new StatusListAssignmentStore() {
+            @Override
+            public void store(final StatusListAssignment record) throws IOException {
+                throw new IOException("simulated storage failure");
+            }
+        };
+        failing.setId("failing");
+        failing.setStorage(storageService);
+        failing.initialize();
+
+        ActionTestingSupport.assertEvent(newAction(failing, EXPIRATION).execute(requestCtx), EventIds.IO_ERROR);
+    }
+
+    @Test(expectedExceptions = ComponentInitializationException.class)
+    public void testInitFailsWithoutStore() throws ComponentInitializationException {
+        final AssignIndex a = new AssignIndex();
+        a.setExpirationLookupStrategy(prc -> EXPIRATION);
+        a.setDetailsLookupStrategy(prc -> DETAILS);
+        a.initialize();
+    }
+
+    @Test(expectedExceptions = ComponentInitializationException.class)
+    public void testInitFailsWithoutExpirationStrategy() throws ComponentInitializationException {
+        final AssignIndex a = new AssignIndex();
+        a.setStatusListAssignmentStore(store);
+        a.setDetailsLookupStrategy(prc -> DETAILS);
+        a.initialize();
+    }
+
+    @Test(expectedExceptions = ComponentInitializationException.class)
+    public void testInitFailsWithoutDetailsStrategy() throws ComponentInitializationException {
+        final AssignIndex a = new AssignIndex();
+        a.setStatusListAssignmentStore(store);
+        a.setExpirationLookupStrategy(prc -> EXPIRATION);
+        a.initialize();
+    }
+
+}
diff --git a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/statuslist/storage/StatusListAssignmentStoreTest.java b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/statuslist/storage/StatusListAssignmentStoreTest.java
index 6a44197..d2bc4e0 100644
--- a/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/statuslist/storage/StatusListAssignmentStoreTest.java
+++ b/openid-vci-impl/src/test/java/org/geant/shibboleth/plugin/openidvci/statuslist/storage/StatusListAssignmentStoreTest.java
@@ -278,4 +278,39 @@ public class StatusListAssignmentStoreTest {
         }
     }
 
+    @Test
+    public void testTwoNodesTakeDistinctPositions() throws Exception {
+        final StatusListAssignmentStore other = newStore();
+        final int records = 1000;
+        final ExecutorService pool = Executors.newFixedThreadPool(8);
+        try {
+            final List<Future<?>> writes = new ArrayList<>();
+            for (int i = 0; i < records; i++) {
+                final long index = i;
+                final StatusListAssignmentStore node = i % 2 == 0 ? store : other;
+                writes.add(pool.submit(() -> {
+                    node.store(record("2027-02", List.of(index)));
+                    return null;
+                }));
+            }
+            for (final Future<?> write : writes) {
+                write.get();
+            }
+        } finally {
+            pool.shutdown();
+            other.destroy();
+        }
+
+        final StatusListAssignments page = store.read(0, records);
+        Assert.assertEquals(page.getHighWater(), records);
+        final Set<Long> positions = new HashSet<>();
+        final Set<Long> indices = new HashSet<>();
+        for (final StatusListAssignment r : page.getRecords()) {
+            positions.add(r.getSeq());
+            indices.addAll(r.getIndices());
+        }
+        Assert.assertEquals(positions.size(), records, "Two records took the same position");
+        Assert.assertEquals(indices.size(), records, "A record was lost");
+    }
+
 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list