Skip to content

Add unit tests for Base64Url encode and decode methods in Core#6804

Merged
RickWinter merged 4 commits intomainfrom
copilot/add-unit-tests-base64url-methods
Oct 23, 2025
Merged

Add unit tests for Base64Url encode and decode methods in Core#6804
RickWinter merged 4 commits intomainfrom
copilot/add-unit-tests-base64url-methods

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Oct 22, 2025

  • Understand the Base64Url encoding/decoding implementation in base64.hpp
  • Review existing base64_test.cpp structure and test patterns
  • Build and run existing tests to establish baseline
  • Add comprehensive unit tests for Base64Url::Base64UrlEncode in base64_test.cpp
  • Add comprehensive unit tests for Base64Url::Base64UrlDecode in base64_test.cpp
  • Test edge cases (empty input, padding scenarios, invalid input)
  • Test roundtrip encode/decode
  • Build and verify all tests pass
  • Run code coverage to verify new tests cover the Base64Url methods
  • Fix clang-format issues
  • Fix misleading comments about Base64 encodings

Summary

Successfully added 8 comprehensive unit tests (222 lines) for Base64Url encode/decode methods in azure-core with proper formatting and accurate comments.

Test Cases:

  1. BasicEncode - Empty input, padding removal (1-3 bytes), special char replacement
  2. BasicDecode - Empty input, 1-3 bytes decode, URL-safe character handling
  3. RoundtripEncodeDecode - Random data roundtrip for lengths 0-1000 bytes
  4. SpecialCharacterReplacement - Verifies + → -, / → _ for all byte values
  5. PaddingHandling - Tests padding removal/restoration for all modulo scenarios
  6. InvalidDecodeInput - Error handling for invalid lengths and characters
  7. ComparisonWithStandardBase64 - Confirms Base64Url vs Base64 differences
  8. KnownVectors - Tests with known good encodings (e.g., "hello")

Recent fixes:

  • Applied clang-format to comply with .clang-format configuration
  • Corrected misleading comment about Base64 encoding (line 217)
  • Updated test data in KnownVectors test to use {0xFB, 0xFF, 0xFE} which correctly demonstrates both + and / replacement (Standard Base64: "+//+", Base64Url: "-__-")
Original prompt

This section details on the original issue you should resolve

<issue_title>Add unit tests for Base64Url encode and decode methods directly in Core.</issue_title>
<issue_description>This PR being green in CI highlights a test gap:
#5420

These functions are indirectly covered by some tests in Attestation, but we shouldn't be relying on them solely, as it isn't thorough enough in verifying correctness of the actual encoding/decoding.

TEST(SerializationTests, TestDeserializePrimitivesBase64Url)
{
std::string testData("Test Data");
std::string encodedData = Azure::Core::_internal::Base64Url::Base64UrlEncode(
std::vector<uint8_t>(testData.begin(), testData.end()));

For whatever reason, the base64.hpp header file doesn't show up in the Code Coverage results:
https://dev.azure.com/azure-sdk/public/_build/results?buildId=3571303&view=codecoverage-tab
image

Only the source file shows up, which has decent coverage numbers:
image

cc @RickWinter, @danieljurek </issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #5424


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: RickWinter <4430337+RickWinter@users.noreply.github.com>
Copilot AI changed the title [WIP] Add unit tests for Base64Url encode and decode methods Add unit tests for Base64Url encode and decode methods in Core Oct 22, 2025
Copilot AI requested a review from RickWinter October 22, 2025 21:43
Comment thread sdk/core/azure-core/test/ut/base64_test.cpp
Co-authored-by: RickWinter <4430337+RickWinter@users.noreply.github.com>
Comment thread sdk/core/azure-core/test/ut/base64_test.cpp
@RickWinter RickWinter marked this pull request as ready for review October 22, 2025 22:15
@RickWinter RickWinter requested a review from antkmsft as a code owner October 22, 2025 22:15
Copilot AI review requested due to automatic review settings October 22, 2025 22:15
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 adds comprehensive unit tests for the Base64Url encoding and decoding methods in azure-core, addressing a test coverage gap where these functions were only indirectly tested through the Attestation SDK.

Key changes:

  • Added 8 new test cases covering Base64Url encode/decode functionality with 222 lines of test code
  • Tests cover basic operations, edge cases, special character replacement, padding handling, invalid input, and roundtrip verification
  • Applied clang-format to ensure code formatting compliance

Comment thread sdk/core/azure-core/test/ut/base64_test.cpp Outdated
Comment thread sdk/core/azure-core/test/ut/base64_test.cpp Outdated
Co-authored-by: RickWinter <4430337+RickWinter@users.noreply.github.com>
@antkmsft
Copy link
Copy Markdown
Member

@microsoft-github-policy-service rerun

@antkmsft
Copy link
Copy Markdown
Member

/check-enforcer evaluate

@RickWinter RickWinter merged commit 32b67d1 into main Oct 23, 2025
39 checks passed
@RickWinter RickWinter deleted the copilot/add-unit-tests-base64url-methods branch October 23, 2025 18:38
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.

Add unit tests for Base64Url encode and decode methods directly in Core.

5 participants