Skip to content

236 - Implement EntityDescriptor attribute 'cacheDuration' as a 'Duration Period' #255

Open
Revsgaard wants to merge 1 commit into
mainfrom
236-implement-entitydescriptor-attribute-cacheduration-as-a-duration-period
Open

236 - Implement EntityDescriptor attribute 'cacheDuration' as a 'Duration Period' #255
Revsgaard wants to merge 1 commit into
mainfrom
236-implement-entitydescriptor-attribute-cacheduration-as-a-duration-period

Conversation

@Revsgaard
Copy link
Copy Markdown
Member

Issue #236

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements the cacheDuration attribute for SAML2 EntityDescriptor and EntitiesDescriptor classes as an XML Schema duration period. The attribute indicates how long metadata consumers should cache metadata before attempting to re-fetch it.

  • Adds CacheDuration property with XML Schema duration validation to EntityDescriptor and EntitiesDescriptor classes
  • Implements regex-based validation for XML Schema duration format with proper error handling
  • Updates XML serialization and deserialization to support the new attribute

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
Saml2MetadataConstants.cs Adds the CacheDuration constant for metadata attribute
EntityDescriptor.cs Implements CacheDuration property with validation, XML serialization, and deserialization support
EntitiesDescriptor.cs Implements CacheDuration property with validation and XML serialization support

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

/// [Optional]
/// Optional attribute indicates how long a metadata consumer should cache this metadata before attempting to re-fetch.
/// Value must be an XML Schema duration (https://www.w3.org/TR/xmlschema-2/#duration). Example: P1D, PT12H, P2Y3M.
/// Regex used for validation: ^-?P(\d*Y)?(\d*M)?(\d*D)?(T(\d*H)?(\d*M)?(\d*S)?)?$
Copy link

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex pattern in the documentation (line 61) does not match the actual regex implementation. The documentation shows (\d*Y)?(\d*M)?(\d*D)? but the implementation uses (\d+Y)?(\d+M)?(\d+W)?(\d+D)? with \d+ instead of \d* and includes (\d+W)? for weeks.

Suggested change
/// Regex used for validation: ^-?P(\d*Y)?(\d*M)?(\d*D)?(T(\d*H)?(\d*M)?(\d*S)?)?$
/// Regex used for validation: ^-?P(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T(\d+H)?(\d+M)?(\d+S)?)?$

Copilot uses AI. Check for mistakes.
Comment on lines +78 to +79
// Require at least one date or time component after 'P' using a lookahead. See https://www.w3.org/TR/xmlschema-2/#duration
private static readonly Regex CacheDurationRegex = new Regex(@"^-?P(?=\d|T)(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T(\d+H)?(\d+M)?(\d+S)?)?$", RegexOptions.Compiled);
Copy link

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment and regex are placed between the private field declaration and the next property. This breaks the logical grouping of the CacheDuration property members. Move the regex and its comment to immediately follow the private field declaration at line 77.

Suggested change
// Require at least one date or time component after 'P' using a lookahead. See https://www.w3.org/TR/xmlschema-2/#duration
private static readonly Regex CacheDurationRegex = new Regex(@"^-?P(?=\d|T)(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T(\d+H)?(\d+M)?(\d+S)?)?$", RegexOptions.Compiled);
// Require at least one date or time component after 'P' using a lookahead. See https://www.w3.org/TR/xmlschema-2/#duration
private static readonly Regex CacheDurationRegex = new Regex(@"^-?P(?=\d|T)(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T(\d+H)?(\d+M)?(\d+S)?)?$", RegexOptions.Compiled);

Copilot uses AI. Check for mistakes.
/// [Optional]
/// Optional attribute indicates how long a metadata consumer should cache this metadata before attempting to re-fetch.
/// Value must be an XML Schema duration (https://www.w3.org/TR/xmlschema-2/#duration). Example: P1D, PT12H, P2Y3M.
/// Regex used for validation: ^-?P(\d*Y)?(\d*M)?(\d*D)?(T(\d*H)?(\d*M)?(\d*S)?)?$
Copy link

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regex pattern in the documentation (line 57) does not match the actual regex implementation. The documentation shows (\d*Y)?(\d*M)?(\d*D)? but the implementation uses (\d+Y)?(\d+M)?(\d+W)?(\d+D)? with \d+ instead of \d* and includes (\d+W)? for weeks.

Suggested change
/// Regex used for validation: ^-?P(\d*Y)?(\d*M)?(\d*D)?(T(\d*H)?(\d*M)?(\d*S)?)?$
/// Regex used for validation: ^-?P(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T(\d+H)?(\d+M)?(\d+S)?)?$

Copilot uses AI. Check for mistakes.
Comment on lines +74 to +75
// Require at least one date or time component after 'P' using a lookahead. See https://www.w3.org/TR/xmlschema-2/#duration
private static readonly Regex CacheDurationRegex = new Regex(@"^-?P(?=\d|T)(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T(\d+H)?(\d+M)?(\d+S)?)?$", RegexOptions.Compiled);
Copy link

Copilot AI Sep 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment and regex are placed between the private field declaration and the next property. This breaks the logical grouping of the CacheDuration property members. Move the regex and its comment to immediately follow the private field declaration at line 73.

Suggested change
// Require at least one date or time component after 'P' using a lookahead. See https://www.w3.org/TR/xmlschema-2/#duration
private static readonly Regex CacheDurationRegex = new Regex(@"^-?P(?=\d|T)(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T(\d+H)?(\d+M)?(\d+S)?)?$", RegexOptions.Compiled);
// Require at least one date or time component after 'P' using a lookahead. See https://www.w3.org/TR/xmlschema-2/#duration
private static readonly Regex CacheDurationRegex = new Regex(@"^-?P(?=\d|T)(\d+Y)?(\d+M)?(\d+W)?(\d+D)?(T(\d+H)?(\d+M)?(\d+S)?)?$", RegexOptions.Compiled);

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement EntityDescriptor attribute 'cacheDuration' as a 'Duration Period'

2 participants