-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update pattern for testing scopes (#44040)
* Update pattern for testing scopes Fixes #43895 * spotless
- Loading branch information
Showing
2 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...entity/azure-identity/src/test/java/com/azure/identity/implementation/ScopeUtilTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
package com.azure.identity.implementation; | ||
|
||
import com.azure.identity.implementation.util.ScopeUtil; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
public class ScopeUtilTests { | ||
|
||
@ParameterizedTest | ||
@MethodSource("validScopes") | ||
public void validScopes(String scope) { | ||
assertDoesNotThrow(() -> ScopeUtil.validateScope(scope)); | ||
|
||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("invalidScopes") | ||
public void validInvalidScopes(String scope) { | ||
assertThrows(IllegalArgumentException.class, () -> ScopeUtil.validateScope(scope)); | ||
|
||
} | ||
|
||
static Stream<String> validScopes() { | ||
return Stream.of("https://vaults.azure.net/.default", "https://management.core.windows.net//.default", | ||
"https://graph.microsoft.com/User.Read", "api://app-id-has-hyphens-and-1234567890s/user_impersonation"); | ||
} | ||
|
||
static Stream<String> invalidScopes() { | ||
return Stream.of("api://app-id-has-hyphens-and-1234567890s/invalid scope", | ||
"api://app-id-has-hyphens-and-1234567890s/invalid\"scope", | ||
"api://app-id-has-hyphens-and-1234567890s/invalid\\scope"); | ||
} | ||
} |