Skip to content

Commit d963e30

Browse files
iarekkCopilot
andauthored
Categorize managed-identity E2E tests and exclude them from the PR build (#3923)
* Categorize managed-identity E2E tests and exclude them from the PR build The `AcquireTokenManagedIdentity` E2E test acquires a token for a user-assigned managed identity via IMDS, so it requires an MI assigned to the build host. It passes on the official OneBranch pipeline (VM-based agents that have the MI) but fails on Microsoft-hosted agents (no MI, IMDS returns "Identity not found"). Following the MSAL approach of categorizing MI tests and running them only where an MI is available: - Add a shared `TestCategories.ManagedIdentity` ("MI_E2E") constant and tag the `AcquireTokenManagedIdentity` class with `[Trait("Category", "MI_E2E")]`. - Parameterize `template-run-unit-tests.yaml` with `e2eTestFilterCriteria` (default empty, so the release build and any other consumer are unaffected). - The PR build (azure-pipelines.yml) passes `Category!=MI_E2E` to exclude the MI tests, which run on Microsoft-hosted agents. The official OneBranch pipeline uses its own inline VSTest steps and is not affected, so it continues to run the MI tests on VM-based agents. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Trigger ADO PR pipeline Empty commit to kick off the newly added ADO PR pipeline trigger. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 1253aee commit d963e30

4 files changed

Lines changed: 37 additions & 0 deletions

File tree

azure-pipelines.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,8 @@ jobs:
2626
- template: build/template-install-dependencies.yaml
2727
- template: build/template-build.yaml
2828
- template: build/template-run-unit-tests.yaml
29+
parameters:
30+
# Exclude managed-identity E2E tests: they require an MI assigned to the
31+
# host (IMDS), which Microsoft-hosted agents do not have. They still run in
32+
# the official OneBranch pipeline on VM-based agents that have the MI.
33+
e2eTestFilterCriteria: 'Category!=MI_E2E'

build/template-run-unit-tests.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
# template-run-unit-tests.yaml
22
# Run all unit tests across the IdWeb project
33

4+
parameters:
5+
# VSTest filter applied to the E2E test run. Empty by default so every consumer
6+
# (e.g. the release build) runs the full E2E suite. The PR build passes a filter
7+
# to exclude tests that cannot run on Microsoft-hosted agents (e.g. managed
8+
# identity tests, which require an MI assigned to the host: Category!=MI_E2E).
9+
- name: e2eTestFilterCriteria
10+
type: string
11+
default: ''
12+
413
steps:
514

615
- task: VSTest@2
@@ -38,6 +47,7 @@ steps:
3847
tests\E2E Tests\TokenAcquirerTests\bin\**\TokenAcquirerTests.dll
3948
tests\E2E Tests\NET 7 tests\IntegrationTests\bin\**\IntegrationTests.dll
4049
searchFolder: '$(System.DefaultWorkingDirectory)'
50+
testFiltercriteria: '${{ parameters.e2eTestFilterCriteria }}'
4151
rerunFailedTests: true
4252
rerunMaxAttempts: '3'
4353
runInParallel: false

tests/E2E Tests/TokenAcquirerTests/TokenAcquirer.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ private static async Task CreateGraphClientAndAssertAsync(TokenAcquirerFactory t
551551
}
552552

553553
[Collection(nameof(TokenAcquirerFactorySingletonProtection))]
554+
[Trait("Category", TestCategories.ManagedIdentity)]
554555
public class AcquireTokenManagedIdentity
555556
{
556557
[OnlyOnAzureDevopsFact]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
namespace Microsoft.Identity.Web.Test.Common
5+
{
6+
/// <summary>
7+
/// Well-known xUnit trait categories (used with <c>[Trait("Category", ...)]</c>)
8+
/// so that specific groups of tests can be included or excluded from a test run
9+
/// via the VSTest <c>testFilterCriteria</c> (for example <c>Category!=MI_E2E</c>).
10+
/// </summary>
11+
public static class TestCategories
12+
{
13+
/// <summary>
14+
/// Tests that require a real Azure managed identity to be assigned to the host
15+
/// (they call the IMDS endpoint). These pass on the official pipeline, which runs
16+
/// on VM-based agents with a managed identity, but cannot run on Microsoft-hosted
17+
/// agents that have no managed identity, so they are filtered out there.
18+
/// </summary>
19+
public const string ManagedIdentity = "MI_E2E";
20+
}
21+
}

0 commit comments

Comments
 (0)