diff --git a/eng/common/TestResources/deploy-test-resources.yml b/eng/common/TestResources/deploy-test-resources.yml index b580d73f1406..b875a806b143 100644 --- a/eng/common/TestResources/deploy-test-resources.yml +++ b/eng/common/TestResources/deploy-test-resources.yml @@ -13,7 +13,7 @@ parameters: # "TestApplicationId": "", # "TestApplicationSecret": "", # "ProvisionerApplicationId": "", -# "ProvisoinerApplicationSecret": "", +# "ProvisionerApplicationSecret": "", # "Environment": "AzureCloud | AzureGov | AzureChina | " # } diff --git a/eng/common/Update-Change-Log.ps1 b/eng/common/Update-Change-Log.ps1 index d50316f223b7..a819a05e8bb2 100644 --- a/eng/common/Update-Change-Log.ps1 +++ b/eng/common/Update-Change-Log.ps1 @@ -27,10 +27,10 @@ function Get-ChangelogPath($Path) { # Check if CHANGELOG.md is present in path $ChangeLogPath = Join-Path -Path $Path -ChildPath "CHANGELOG.md" - if ((Test-Path -Path $ChangeLogPath) -eq $False){ + if ((Test-Path -Path $ChangeLogPath) -eq $False) { # Check if change log exists with name HISTORY.md $ChangeLogPath = Join-Path -Path $Path -ChildPath "HISTORY.md" - if ((Test-Path -Path $ChangeLogPath) -eq $False){ + if ((Test-Path -Path $ChangeLogPath) -eq $False) { Write-Host "Change log is not found in path[$Path]" exit(1) } @@ -45,7 +45,7 @@ function Get-VersionTitle($Version, $Unreleased) { # Generate version title $newVersionTitle = "## $Version $UNRELEASED_TAG" - if ($Unreleased -eq $False){ + if ($Unreleased -eq $False) { $releaseDate = Get-Date -Format "(yyyy-MM-dd)" $newVersionTitle = "## $Version $releaseDate" } @@ -67,10 +67,10 @@ function Get-NewChangeLog( [System.Collections.ArrayList]$ChangelogLines, $Versi # Version increment tool passes replaceversion as False and Unreleased as True $is_version_increment = $ReplaceVersion -eq $False -and $Unreleased -eq $True - for(; $Index -lt $ChangelogLines.Count; $Index++){ - if (Version-Matches($ChangelogLines[$Index])){ + for (; $Index -lt $ChangelogLines.Count; $Index++) { + if (Version-Matches($ChangelogLines[$Index])) { # Find current title in change log - if( -not $CurrentTitle){ + if( -not $CurrentTitle) { $CurrentTitle = $ChangelogLines[$Index] $CurrentIndex = $Index Write-Host "Current Version title: $CurrentTitle" @@ -80,7 +80,7 @@ function Get-NewChangeLog( [System.Collections.ArrayList]$ChangelogLines, $Versi # update change log script is triggered for all packages with current version for Java ( or any language where version is maintained in common file) # and this can cause an issue if someone changes changelog manually to prepare for release without updating actual version in central version file # Do not add new line or replace existing title when version is already present and script is triggered to add new line - if ($is_version_increment -and $ChangelogLines[$Index].Contains($Version)){ + if ($is_version_increment -and $ChangelogLines[$Index].Contains($Version)) { Write-Host "Version is already present in change log." exit(0) } @@ -90,26 +90,24 @@ function Get-NewChangeLog( [System.Collections.ArrayList]$ChangelogLines, $Versi # Generate version title $newVersionTitle = Get-VersionTitle -Version $Version -Unreleased $Unreleased - if( $newVersionTitle -eq $CurrentTitle){ + if( $newVersionTitle -eq $CurrentTitle) { Write-Host "No change is required in change log. Version is already present." exit(0) } - - - if (($ReplaceVersion -eq $True) -and ($Unreleased -eq $False) -and (-not $CurrentTitle.Contains($UNRELEASED_TAG))){ + if (($ReplaceVersion -eq $True) -and ($Unreleased -eq $False) -and $CurrentTitle.Contains($version) -and (-not $CurrentTitle.Contains($UNRELEASED_TAG))) { Write-Host "Version is already present in change log with a release date." exit(0) } # if current version title already has new version then we should replace title to update it - if ($CurrentTitle.Contains($Version) -and $ReplaceVersion -eq $False){ + if ($CurrentTitle.Contains($Version) -and $ReplaceVersion -eq $False) { Write-Host "Version is already present in title. Updating version title" $ReplaceVersion = $True } # if version is already found and not replacing then nothing to do - if ($ReplaceVersion -eq $False){ + if ($ReplaceVersion -eq $False) { Write-Host "Adding version title $newVersionTitle" $ChangelogLines.insert($CurrentIndex, "") $ChangelogLines.insert($CurrentIndex, "") @@ -121,24 +119,28 @@ function Get-NewChangeLog( [System.Collections.ArrayList]$ChangelogLines, $Versi $ChangelogLines[$CurrentIndex] = $newVersionTitle } - return $ChangelogLines + return $ChangelogLines } # Make sure path is valid -if ((Test-Path -Path $ChangeLogPath) -eq $False){ +if ((Test-Path -Path $ChangeLogPath) -eq $False) { Write-Host "Change log path is invalid. [$ChangeLogPath]" exit(1) } # probe change log path if path is directory -if (Test-Path -Path $ChangeLogPath -PathType Container) -{ +if (Test-Path -Path $ChangeLogPath -PathType Container) { $ChangeLogPath = Get-ChangelogPath -Path $ChangeLogPath } # Read current change logs and add/update version $ChangelogLines = [System.Collections.ArrayList](Get-Content -Path $ChangeLogPath) + +if ($null -eq $ChangelogLines) { + $ChangelogLines = @() +} + $NewContents = Get-NewChangeLog -ChangelogLines $ChangelogLines -Version $Version -Unreleased $Unreleased -ReplaceVersion $ReplaceVersion Write-Host "Writing change log to file [$ChangeLogPath]" diff --git a/eng/common/pipelines/templates/steps/create-pull-request.yml b/eng/common/pipelines/templates/steps/create-pull-request.yml index 790de92bcbe5..ce0680ff8f99 100644 --- a/eng/common/pipelines/templates/steps/create-pull-request.yml +++ b/eng/common/pipelines/templates/steps/create-pull-request.yml @@ -12,6 +12,8 @@ parameters: WorkingDirectory: $(System.DefaultWorkingDirectory) PRTitle: not-specified ScriptDirectory: eng/common/scripts + GHReviewersVariable: '' + GHTeamReviewersVariable: '' steps: @@ -63,3 +65,17 @@ steps: -PRBranch "${{ parameters.PRBranchName }}" -AuthToken "$(azuresdk-github-pat)" -PRTitle "${{ parameters.PRTitle }}" + +- task: PowerShell@2 + displayName: Tag a Reviewer on PR + inputs: + pwsh: true + workingDirectory: ${{ parameters.WorkingDirectory }} + filePath: ${{ parameters.ScriptDirectory }}/add-pullrequest-reviewers.ps1 + arguments: > + -RepoOwner "${{ parameters.RepoOwner }}" + -RepoName "${{ parameters.RepoName }}" + -AuthToken "$(azuresdk-github-pat)" + -GitHubUsers "$(${{ parameters.GHReviewersVariable }})" + -GitHubTeams "$(${{ parameters.GHTeamReviewersVariable }})" + -PRNumber "$(Submitted.PullRequest.Number)" diff --git a/eng/common/pipelines/templates/steps/daily-dev-build-variable.yml b/eng/common/pipelines/templates/steps/daily-dev-build-variable.yml new file mode 100644 index 000000000000..2e10f695c998 --- /dev/null +++ b/eng/common/pipelines/templates/steps/daily-dev-build-variable.yml @@ -0,0 +1,12 @@ +# This script fragment is used across our repos to set a variable "SetDevVersion" which +# is used when this pipeline is going to be generating and publishing daily dev builds. + +steps: +- pwsh: | + $setDailyDevBuild = "false" + if (('$(Build.Reason)' -eq 'Schedule') -and ('$(System.TeamProject)' -eq 'internal')) { + $setDailyDevBuild = "true" + } + echo "##vso[task.setvariable variable=SetDevVersion]$setDailyDevBuild" + displayName: "Setup Versioning Properties" + condition: eq(variables['SetDevVersion'], '') diff --git a/eng/common/pipelines/templates/steps/docs-metadata-release.yml b/eng/common/pipelines/templates/steps/docs-metadata-release.yml index 6ff9f84ff3ee..a9ff8c4e17b4 100644 --- a/eng/common/pipelines/templates/steps/docs-metadata-release.yml +++ b/eng/common/pipelines/templates/steps/docs-metadata-release.yml @@ -12,6 +12,8 @@ parameters: ArtifactName: '' Language: '' DocRepoDestinationPath: '' #usually docs-ref-services/ + GHReviewersVariable: '' + GHTeamReviewersVariable: '' # externally set, as eng-common does not have the identity-resolver. Run as pre-step steps: - pwsh: | @@ -56,3 +58,5 @@ steps: BaseBranchName: smoke-test WorkingDirectory: ${{ parameters.WorkingDirectory }}/repo ScriptDirectory: ${{ parameters.WorkingDirectory }}/${{ parameters.ScriptDirectory }} + GHReviewersVariable: ${{ parameters.GHReviewersVariable }} + GHTeamReviewersVariable: ${{ parameters.GHTeamReviewersVariable }} diff --git a/eng/common/pipelines/templates/steps/get-pr-owners.yml b/eng/common/pipelines/templates/steps/get-pr-owners.yml new file mode 100644 index 000000000000..a80d5b83b2de --- /dev/null +++ b/eng/common/pipelines/templates/steps/get-pr-owners.yml @@ -0,0 +1,46 @@ +parameters: + TargetVariable: '' + ServiceDirectory: '' + +steps: + - pwsh: | + git clone https://github.com/Azure/azure-sdk-tools.git $(Build.SourcesDirectory)/tools_repo + cd $(Build.SourcesDirectory)/tools_repo + git checkout 564ad63ae72d18422533fa1da9d396e7703c1cb5 + displayName: Setup Identity Resolver + + - pwsh: | + $result = dotnet run -v q -- ` + --aad-app-id-var APP_ID ` + --aad-app-secret-var APP_SECRET ` + --aad-tenant-var AAD_TENANT ` + --kusto-url-var KUSTO_URL ` + --kusto-database-var KUSTO_DB ` + --kusto-table-var KUSTO_TABLE ` + --identity "$(Build.QueuedBy)" + $resolvedIdentity = $result[-1] | ConvertFrom-Json + + Write-Host $resolvedIdentity + + Write-Output "##vso[task.setvariable variable=${{ parameters.TargetVariable }}]$($resolvedIdentity.GithubUserName)" + displayName: 'Resolving Queuing User' + workingDirectory: $(Build.SourcesDirectory)/tools_repo/tools/notification-configuration/identity-resolver + env: + APP_ID: $(notification-aad-app-id) + APP_SECRET: $(notification-aad-secret) + AAD_TENANT: $(notification-aad-tenant) + KUSTO_URL: $(notification-kusto-url) + KUSTO_DB: $(notification-kusto-db) + KUSTO_TABLE: $(notification-kusto-table) + + - pwsh: | + Remove-Item -Force -Recurse $(Build.SourcesDirectory)/tools_repo + displayName: Clean Up Cloned Tools Repo + + - pwsh: | + $originalValue = "$(${{ parameters.TargetVariable }})" + $result = $(Build.SourcesDirectory)/eng/common/scripts/get-codeowners.ps1 -TargetDirectory /sdk/${{ parameters.ServiceDirectory }}/ -RootDirectory $(Build.SourcesDirectory) + if ($result) { + Write-Output "##vso[task.setvariable variable=${{ parameters.TargetVariable }}]$originalValue,$result" + } + displayName: Add CodeOwners if Present \ No newline at end of file diff --git a/eng/common/pipelines/templates/steps/verify-links.yml b/eng/common/pipelines/templates/steps/verify-links.yml index 1a99350f0161..a3d385becefc 100644 --- a/eng/common/pipelines/templates/steps/verify-links.yml +++ b/eng/common/pipelines/templates/steps/verify-links.yml @@ -1,5 +1,7 @@ parameters: Directory: 'not-specified' + IgnoreLinksFile: "$(Build.SourcesDirectory)/eng/ignore-links.txt" + steps: - task: PowerShell@2 @@ -9,4 +11,4 @@ steps: workingDirectory: $(Build.SourcesDirectory)/${{ parameters.Directory }} filePath: eng/common/scripts/Verify-Links.ps1 arguments: > - -urls $(dir -r -i *.md) -rootUrl "file://$(Build.SourcesDirectory)/${{ parameters.Directory }}" + -urls $(dir -r -i *.md) -rootUrl "file://$(Build.SourcesDirectory)/${{ parameters.Directory }}" -recursive:$false -ignoreLinksFile ${{ parameters.IgnoreLinksFile }} diff --git a/eng/common/scripts/Submit-PullRequest.ps1 b/eng/common/scripts/Submit-PullRequest.ps1 index ef2a6f545061..5edabc599a99 100644 --- a/eng/common/scripts/Submit-PullRequest.ps1 +++ b/eng/common/scripts/Submit-PullRequest.ps1 @@ -58,6 +58,9 @@ $resp | Write-Verbose if ($resp.Count -gt 0) { Write-Host -f green "Pull request already exists $($resp[0].html_url)" + + # setting variable to reference the pull request by number + Write-Host "##vso[task.setvariable variable=Submitted.PullRequest.Number]$($resp[0].number)" } else { $data = @{ @@ -80,4 +83,7 @@ else { $resp | Write-Verbose Write-Host -f green "Pull request created https://github.com/$RepoOwner/$RepoName/pull/$($resp.number)" + + # setting variable to reference the pull request by number + Write-Host "##vso[task.setvariable variable=Submitted.PullRequest.Number]$($resp.number)" } diff --git a/eng/common/scripts/Verify-ChangeLog.ps1 b/eng/common/scripts/Verify-ChangeLog.ps1 index 816a82f5bcb2..26218d988df2 100644 --- a/eng/common/scripts/Verify-ChangeLog.ps1 +++ b/eng/common/scripts/Verify-ChangeLog.ps1 @@ -1,31 +1,48 @@ # Wrapper Script for ChangeLog Verification param ( - [String]$ChangeLogLocation, - [String]$VersionString, - [string]$PackageName, - [string]$ServiceName, - [string]$RepoRoot, - [ValidateSet("net","java","js","python")] - [string]$Language, - [string]$RepoName, - [boolean]$ForRelease=$False + [String]$ChangeLogLocation, + [String]$VersionString, + [string]$PackageName, + [string]$ServiceName, + [string]$RepoRoot, + [ValidateSet("net", "java", "js", "python")] + [string]$Language, + [string]$RepoName, + [boolean]$ForRelease = $False ) +$ProgressPreference = "SilentlyContinue" . (Join-Path $PSScriptRoot SemVer.ps1) Import-Module (Join-Path $PSScriptRoot modules ChangeLog-Operations.psm1) -if ((Test-Path $ChangeLogLocation) -and -not([System.String]::IsNullOrEmpty($VersionString))) +$validChangeLog = $false +if ($ChangeLogLocation -and $VersionString) { - Confirm-ChangeLogEntry -ChangeLogLocation $ChangeLogLocation -VersionString $VersionString -ForRelease $ForRelease + $validChangeLog = Confirm-ChangeLogEntry -ChangeLogLocation $ChangeLogLocation -VersionString $VersionString -ForRelease $ForRelease } -else +else { - Import-Module (Join-Path $PSScriptRoot modules Package-Properties.psm1) - if ([System.String]::IsNullOrEmpty($Language)) + Import-Module (Join-Path $PSScriptRoot modules Package-Properties.psm1) + if ([System.String]::IsNullOrEmpty($Language)) + { + if ($RepoName -match "azure-sdk-for-(?[^-]+)") { - $Language = $RepoName.Substring($RepoName.LastIndexOf('-') + 1) + $Language = $matches["lang"] } + else + { + Write-Error "Failed to set Language automatically. Please pass the appropriate Language as a parameter." + exit 1 + } + } + + $PackageProp = Get-PkgProperties -PackageName $PackageName -ServiceName $ServiceName -Language $Language -RepoRoot $RepoRoot + $validChangeLog = Confirm-ChangeLogEntry -ChangeLogLocation $PackageProp.pkgChangeLogPath -VersionString $PackageProp.pkgVersion -ForRelease $ForRelease +} + +if (!$validChangeLog) +{ + exit 1 +} - $PackageProp = Get-PkgProperties -PackageName $PackageName -ServiceName $ServiceName -Language $Language -RepoRoot $RepoRoot - Confirm-ChangeLogEntry -ChangeLogLocation $PackageProp.pkgChangeLogPath -VersionString $PackageProp.pkgVersion -ForRelease $ForRelease -} \ No newline at end of file +exit 0 \ No newline at end of file diff --git a/eng/common/scripts/add-pullrequest-reviewers.ps1 b/eng/common/scripts/add-pullrequest-reviewers.ps1 new file mode 100644 index 000000000000..00460ce701f0 --- /dev/null +++ b/eng/common/scripts/add-pullrequest-reviewers.ps1 @@ -0,0 +1,79 @@ +param( + [Parameter(Mandatory = $true)] + $RepoOwner, + + [Parameter(Mandatory = $true)] + $RepoName, + + [Parameter(Mandatory = $false)] + $GitHubUsers = "", + + [Parameter(Mandatory = $false)] + $GitHubTeams = "", + + [Parameter(Mandatory = $true)] + $PRNumber, + + [Parameter(Mandatory = $true)] + $AuthToken +) + +# at least one of these needs to be populated +if (-not $GitHubUsers -and -not $GitHubTeams) { + Write-Host "No user provided for addition, exiting." + exit 0 +} + +$userAdditions = @($GitHubUsers.Split(",") | % { $_.Trim() } | ? { return $_ }) +$teamAdditions = @($GitHubTeams.Split(",") | % { $_.Trim() } | ? { return $_ }) + +$headers = @{ + Authorization = "bearer $AuthToken" +} +$uri = "https://api.github.com/repos/$RepoOwner/$RepoName/pulls/$PRNumber/requested_reviewers" + +try { + $resp = Invoke-RestMethod -Headers $headers $uri -MaximumRetryCount 3 +} +catch { + Write-Error "Invoke-RestMethod [$uri] failed with exception:`n$_" + exit 1 +} + +# the response object takes this form: https://developer.github.com/v3/pulls/review_requests/#response-1 +# before we can push a new reviewer, we need to pull the simple Ids out of the complex objects that came back in the response +$userReviewers = @($resp.users | % { return $_.login }) +$teamReviewers = @($resp.teams | % { return $_.slug }) + +if (!$usersReviewers) { $modifiedUserReviewers = @() } else { $modifiedUserReviewers = $usersReviewers.Clone() } +$modifiedUserReviewers += ($modifiedUserReviewers | ? { !$usersReviews.Contains($_) }) + +if ($teamReviewers) { $modifiedTeamReviewers = @() } else { $modifiedTeamReviewers = $teamReviewers.Clone() } +$modifiedTeamReviewers += ($modifiedUserReviewers | ? { !$teamReviewers.Contains($_) }) + +$detectedUserDiffs = Compare-Object -ReferenceObject $userReviewers -DifferenceObject $modifiedUserReviewers +$detectedTeamDiffs = Compare-Object -ReferenceObject $teamReviewers -DifferenceObject $modifiedTeamReviewers + +# Compare-Object returns values when there is a difference between the comparied objects. +# we only want to run the update if there IS a difference. +if ($detectedUserDiffs -or $detectedTeamDiffs) { + $postResp = @{} + + if ($modifiedUserReviewers) { $postResp["reviewers"] = $modifiedUserReviewers } + if ($modifiedTeamReviewers) { $postResp["team_reviewers"] = $modifiedTeamReviewers } + + $postResp = $postResp | ConvertTo-Json + + try { + $resp = Invoke-RestMethod -Method Post -Headers $headers -Body $postResp -Uri $uri -MaximumRetryCount 3 + $resp | Write-Verbose + } + catch { + Write-Error "Unable to update PR reviewers. `n$_" + } +} +else { + $results = $GitHubUsers + $GitHubTeams + Write-Host "Reviewers $results already added. Exiting." + exit(0) +} diff --git a/eng/common/scripts/get-codeowners.ps1 b/eng/common/scripts/get-codeowners.ps1 new file mode 100644 index 000000000000..edbae4cb18c6 --- /dev/null +++ b/eng/common/scripts/get-codeowners.ps1 @@ -0,0 +1,40 @@ +param ( + $TargetDirectory, # should be in relative form from root of repo. EG: sdk/servicebus + $RootDirectory # ideally $(Build.SourcesDirectory) +) + +$codeOwnersLocation = Join-Path $RootDirectory -ChildPath ".github/CODEOWNERS" + +if (!(Test-Path $codeOwnersLocation)) { + Write-Host "Unable to find CODEOWNERS file in target directory $RootDirectory" + exit 1 +} + +$codeOwnersContent = Get-Content $codeOwnersLocation + +$ownedFolders = @{} + +foreach ($contentLine in $codeOwnersContent) { + if (-not $contentLine.StartsWith("#") -and $contentLine){ + $splitLine = $contentLine -split "\s+" + + # CODEOWNERS file can also have labels present after the owner aliases + # gh aliases start with @ in codeowners. don't pass on to API calls + $ownedFolders[$splitLine[0].ToLower()] = ($splitLine[1..$($splitLine.Length)] ` + | ? { $_.StartsWith("@") } ` + | % { return $_.substring(1) }) -join "," + } +} + +$results = $ownedFolders[$TargetDirectory.ToLower()] + +if ($results) { + Write-Host "Discovered code owners for path $TargetDirectory are $results." + return $results +} +else { + Write-Host "Unable to match path $TargetDirectory in CODEOWNERS file located at $codeOwnersLocation." + Write-Host $ownedFolders | ConvertTo-Json + return "" +} + diff --git a/eng/common/scripts/modules/ChangeLog-Operations.psm1 b/eng/common/scripts/modules/ChangeLog-Operations.psm1 index e92070b195b3..5aed584d018b 100644 --- a/eng/common/scripts/modules/ChangeLog-Operations.psm1 +++ b/eng/common/scripts/modules/ChangeLog-Operations.psm1 @@ -11,8 +11,8 @@ function Get-ChangeLogEntries { $changeLogEntries = @{} if (!(Test-Path $ChangeLogLocation)) { - Write-Host "ChangeLog '{0}' was not found" -f $ChangeLogLocation - exit 1 + Write-Error "ChangeLog[${ChangeLogLocation}] does not exist" + return $null } try { @@ -51,14 +51,12 @@ function Get-ChangeLogEntry { [Parameter(Mandatory = $true)] [String]$VersionString ) - $changeLogEntries = Get-ChangeLogEntries -ChangeLogLocation $ChangeLogLocation - if ($changeLogEntries.ContainsKey($VersionString)) { + if ($changeLogEntries -and $changeLogEntries.ContainsKey($VersionString)) { return $changeLogEntries[$VersionString] } - Write-Error "Release Notes for the Specified version ${VersionString} was not found" - exit 1 + return $null } #Returns the changelog for a particular version as string @@ -70,9 +68,16 @@ function Get-ChangeLogEntryAsString { [String]$VersionString ) - $changeLogEntries = Get-ChangeLogEntry -ChangeLogLocation $ChangeLogLocation -VersionString $VersionString - [string]$releaseTitle = $changeLogEntries.ReleaseTitle - [string]$releaseContent = $changeLogEntries.ReleaseContent -Join [Environment]::NewLine + $changeLogEntry = Get-ChangeLogEntry -ChangeLogLocation $ChangeLogLocation -VersionString $VersionString + return ChangeLogEntryAsString $changeLogEntry +} + +function ChangeLogEntryAsString($changeLogEntry) { + if (!$changeLogEntry) { + return "[Missing change log entry]" + } + [string]$releaseTitle = $changeLogEntry.ReleaseTitle + [string]$releaseContent = $changeLogEntry.ReleaseContent -Join [Environment]::NewLine return $releaseTitle, $releaseContent -Join [Environment]::NewLine } @@ -87,27 +92,33 @@ function Confirm-ChangeLogEntry { $changeLogEntry = Get-ChangeLogEntry -ChangeLogLocation $ChangeLogLocation -VersionString $VersionString + if (!$changeLogEntry) { + Write-Error "ChangeLog[${ChangeLogLocation}] does not have an entry for version ${VersionString}." + return $false + } + + Write-Host "Found the following change log entry for version '${VersionString}' in [${ChangeLogLocation}]." + Write-Host "-----" + Write-Host (ChangeLogEntryAsString $changeLogEntry) + Write-Host "-----" + if ([System.String]::IsNullOrEmpty($changeLogEntry.ReleaseStatus)) { - Write-Host ("##[error]Changelog '{0}' has wrong release note title" -f $ChangeLogLocation) - Write-Host "##[info]Ensure the release date is included i.e. (yyyy-MM-dd) or (Unreleased) if not yet released" - exit 1 + Write-Error "Entry does not have a correct release status. Please ensure the status is set to a date '(yyyy-MM-dd)' or '(Unreleased)' if not yet released." + return $false } if ($ForRelease -eq $True) { if ($changeLogEntry.ReleaseStatus -eq "(Unreleased)") { - Write-Host ("##[error]No release date set. Please set a release date with format 'yyyy-MM-dd' in the heading for version '{0}' in the changelog '{1}'." -f $VersionString, $ChangelogLocation) - exit 1 + Write-Error "Entry has no release date set. Please ensure to set a release date with format 'yyyy-MM-dd'." + return $false } if ([System.String]::IsNullOrWhiteSpace($changeLogEntry.ReleaseContent)) { - Write-Host ("##[error]Empty Release Notes for '{0}' in '{1}'" -f $VersionString, $ChangeLogLocation) - Write-Host "##[info]Please ensure there is a release notes entry before releasing the package." - exit 1 + Write-Error "Entry has no content. Please ensure to provide some content of what changed in this version." + return $false } } - - Write-Host $changeLogEntry.ReleaseTitle - Write-Host $changeLogEntry.ReleaseContent + return $true } Export-ModuleMember -Function 'Get-ChangeLogEntries' diff --git a/eng/common/scripts/modules/Package-Properties.psm1 b/eng/common/scripts/modules/Package-Properties.psm1 index dca123f929f7..b9a8eb11780d 100644 --- a/eng/common/scripts/modules/Package-Properties.psm1 +++ b/eng/common/scripts/modules/Package-Properties.psm1 @@ -3,13 +3,24 @@ class PackageProps { [string]$pkgName - [AzureEngSemanticVersion]$pkgVersion + [string]$pkgVersion [string]$pkgDirectoryPath [string]$pkgServiceName [string]$pkgReadMePath [string]$pkgChangeLogPath + [string]$pkgGroup - PackageProps( + PackageProps([string]$pkgName,[string]$pkgVersion,[string]$pkgDirectoryPath,[string]$pkgServiceName) + { + $this.Initialize($pkgName, $pkgVersion, $pkgDirectoryPath, $pkgServiceName) + } + + PackageProps([string]$pkgName,[string]$pkgVersion,[string]$pkgDirectoryPath,[string]$pkgServiceName,[string]$pkgGroup="") + { + $this.Initialize($pkgName, $pkgVersion, $pkgDirectoryPath, $pkgServiceName, $pkgGroup) + } + + hidden [void]Initialize( [string]$pkgName, [string]$pkgVersion, [string]$pkgDirectoryPath, @@ -17,11 +28,7 @@ class PackageProps ) { $this.pkgName = $pkgName - $this.pkgVersion = [AzureEngSemanticVersion]::ParseVersionString($pkgVersion) - if ($this.pkgVersion -eq $null) - { - Write-Error "Invalid version in $pkgDirectoryPath" - } + $this.pkgVersion = $pkgVersion $this.pkgDirectoryPath = $pkgDirectoryPath $this.pkgServiceName = $pkgServiceName @@ -43,8 +50,24 @@ class PackageProps $this.pkgChangeLogPath = $null } } + + hidden [void]Initialize( + [string]$pkgName, + [string]$pkgVersion, + [string]$pkgDirectoryPath, + [string]$pkgServiceName, + [string]$pkgGroup + ) + { + $this.Initialize($pkgName, $pkgVersion, $pkgDirectoryPath, $pkgServiceName) + $this.pkgGroup = $pkgGroup + } } +$ProgressPreference = "SilentlyContinue" + + +Register-PSRepository -Default -ErrorAction:SilentlyContinue Install-Module -Name powershell-yaml -RequiredVersion 0.4.1 -Force -Scope CurrentUser function Extract-PkgProps ($pkgPath, $serviceName, $pkgName, $lang) @@ -126,10 +149,11 @@ function Extract-JavaPkgProps ($pkgPath, $serviceName, $pkgName) $projectData.load($projectPath) $projectPkgName = $projectData.project.artifactId $pkgVersion = $projectData.project.version + $pkgGroup = $projectData.project.groupId if ($projectPkgName -eq $pkgName) { - return [PackageProps]::new($pkgName, $pkgVersion.ToString(), $pkgPath, $serviceName) + return [PackageProps]::new($pkgName, $pkgVersion.ToString(), $pkgPath, $serviceName, $pkgGroup) } } return $null @@ -239,8 +263,14 @@ function Get-PkgListFromYml ($ciYmlPath) { $ciYmlContent = Get-Content $ciYmlPath -Raw $ciYmlObj = ConvertFrom-Yaml $ciYmlContent -Ordered - $artifactsInCI = $ciYmlObj["stages"][0]["parameters"]["Artifacts"] - + if ($ciYmlObj.Contains("stages")) + { + $artifactsInCI = $ciYmlObj["stages"][0]["parameters"]["Artifacts"] + } + elseif ($ciYmlObj.Contains("extends")) + { + $artifactsInCI = $ciYmlObj["extends"]["parameters"]["Artifacts"] + } if ($artifactsInCI -eq $null) { Write-Error "Failed to retrive package names in ci $ciYmlPath" diff --git a/eng/jacoco-test-coverage/pom.xml b/eng/jacoco-test-coverage/pom.xml index b86c61b38567..9c830791f2a5 100644 --- a/eng/jacoco-test-coverage/pom.xml +++ b/eng/jacoco-test-coverage/pom.xml @@ -134,7 +134,7 @@ com.azure azure-identity - 1.1.0-beta.1 + 1.0.9 com.azure diff --git a/eng/versioning/external_dependencies.txt b/eng/versioning/external_dependencies.txt index 4609f9a6eac6..ca70dff13f19 100644 --- a/eng/versioning/external_dependencies.txt +++ b/eng/versioning/external_dependencies.txt @@ -111,7 +111,7 @@ com.microsoft.azure:azure-mgmt-resources;1.3.0 com.microsoft.azure:azure-mgmt-search;1.24.1 com.microsoft.azure:azure-mgmt-storage;1.3.0 com.microsoft.azure:azure-storage;8.0.0 -com.microsoft.azure:msal4j;0.5.0-preview +com.microsoft.azure:msal4j;1.6.1 com.sun.activation:jakarta.activation;1.2.1 io.opentelemetry:opentelemetry-api;0.2.4 io.opentelemetry:opentelemetry-sdk;0.2.4 diff --git a/eng/versioning/version_client.txt b/eng/versioning/version_client.txt index b6a33f9866fb..54135372cbb5 100644 --- a/eng/versioning/version_client.txt +++ b/eng/versioning/version_client.txt @@ -26,7 +26,7 @@ com.azure:azure-data-schemaregistry;1.0.0-beta.2;1.0.0-beta.3 com.azure:azure-data-schemaregistry-avro;1.0.0-beta.2;1.0.0-beta.3 com.azure:azure-data-tables;1.0.0-beta.1;1.0.0-beta.1 com.azure:azure-e2e;1.0.0-beta.1;1.0.0-beta.1 -com.azure:azure-identity;1.0.8;1.1.0-beta.1 +com.azure:azure-identity;1.0.8;1.0.9 com.azure:azure-messaging-eventhubs;5.1.1;5.2.0-beta.1 com.azure:azure-messaging-eventhubs-checkpointstore-blob;1.1.1;1.2.0-beta.1 com.azure:azure-messaging-servicebus;7.0.0-beta.3;7.0.0-beta.4 @@ -66,7 +66,7 @@ com.microsoft.azure:spring-data-cosmosdb;2.3.0;2.3.1-beta.1 # Format; # unreleased_:;dependency-version # note: The unreleased dependencies will not be manipulated with the automatic PR creation code. - +unreleased_com.azure:azure-identity;1.0.9 unreleased_com.azure:azure-messaging-servicebus;7.0.0-beta.4 # Released Beta dependencies: Copy the entry from above, prepend "beta_", remove the current diff --git a/sdk/e2e/pom.xml b/sdk/e2e/pom.xml index b9b34b1049dc..e35512e985e1 100644 --- a/sdk/e2e/pom.xml +++ b/sdk/e2e/pom.xml @@ -33,7 +33,7 @@ com.azure azure-identity - 1.1.0-beta.1 + 1.0.9 com.azure diff --git a/sdk/eventhubs/microsoft-azure-eventhubs/pom.xml b/sdk/eventhubs/microsoft-azure-eventhubs/pom.xml index 585745111cd6..c8bbb53d00fb 100644 --- a/sdk/eventhubs/microsoft-azure-eventhubs/pom.xml +++ b/sdk/eventhubs/microsoft-azure-eventhubs/pom.xml @@ -76,7 +76,7 @@ com.microsoft.azure msal4j - 0.5.0-preview + 1.6.1 test diff --git a/sdk/eventhubs/microsoft-azure-eventhubs/src/test/java/com/microsoft/azure/eventhubs/sendrecv/MsalTest.java b/sdk/eventhubs/microsoft-azure-eventhubs/src/test/java/com/microsoft/azure/eventhubs/sendrecv/MsalTest.java index 6e9db81aeb3f..ac8435634cf8 100644 --- a/sdk/eventhubs/microsoft-azure-eventhubs/src/test/java/com/microsoft/azure/eventhubs/sendrecv/MsalTest.java +++ b/sdk/eventhubs/microsoft-azure-eventhubs/src/test/java/com/microsoft/azure/eventhubs/sendrecv/MsalTest.java @@ -5,7 +5,6 @@ import com.microsoft.aad.msal4j.ClientCredentialFactory; import com.microsoft.aad.msal4j.ClientCredentialParameters; -import com.microsoft.aad.msal4j.ClientSecret; import com.microsoft.aad.msal4j.ConfidentialClientApplication; import com.microsoft.aad.msal4j.IAuthenticationResult; import com.microsoft.azure.eventhubs.AzureActiveDirectoryTokenProvider; @@ -18,7 +17,7 @@ //import org.junit.Test; /** - * These JUnit test cases are all commented out by default because they can only be run with special setup. + * These JUnit test cases are all commented out by default because they can only be run with special setup. * They extract the namespace (endpoint) and event hub name from the connection string in the environment variable * which all test cases use, but they assume that the namespace (or event hub) has been set up with special permissions. * Within the AAD directory indicated by "authority", there is a registered application with id "clientId" and a secret @@ -29,7 +28,7 @@ public class MsalTest extends AadBase { private final String authority = "https://login.windows.net/replaceWithTenantIdGuid"; private final String clientId = "replaceWithClientIdGuid"; private final String clientSecret = "replaceWithClientSecret"; - + //@Test public void runSendReceiveWithAuthCallbackTest() throws Exception { final AuthCallback callback = new AuthCallback(this.clientId, this.clientSecret); @@ -38,7 +37,7 @@ public void runSendReceiveWithAuthCallbackTest() throws Exception { innerTest(ehc); } - + //@Test public void runSendReceiveWithAADTokenProvider() throws Exception { final AuthCallback callback = new AuthCallback(this.clientId, this.clientSecret); @@ -46,26 +45,26 @@ public void runSendReceiveWithAADTokenProvider() throws Exception { new AzureActiveDirectoryTokenProvider(callback, this.authority, null); final EventHubClient ehc = EventHubClient.createWithTokenProvider(MsalTest.endpoint, MsalTest.eventHubName, aadTokenProvider, this.executorService, null).get(); - + innerTest(ehc); } - + //@Test public void runSendReceiveWithCustomTokenProvider() throws Exception { final CustomTokenProvider tokenProvider = new CustomTokenProvider(this.authority, this.clientId, this.clientSecret); final EventHubClient ehc = EventHubClient.createWithTokenProvider(MsalTest.endpoint, MsalTest.eventHubName, tokenProvider, this.executorService, null).get(); - + innerTest(ehc); } - + @Override String tokenGet(final String authority, final String clientId, final String clientSecret, final String audience, final String extra) throws MalformedURLException, InterruptedException, ExecutionException { - ConfidentialClientApplication app = ConfidentialClientApplication.builder(clientId, new ClientSecret(clientSecret)) + ConfidentialClientApplication app = ConfidentialClientApplication.builder(clientId, ClientCredentialFactory.createFromSecret(clientSecret)) .authority(authority) .build(); - + ClientCredentialParameters parameters = ClientCredentialParameters.builder(Collections.singleton(audience + extra)).build(); IAuthenticationResult result = app.acquireToken(parameters).get(); diff --git a/sdk/identity/azure-identity/CHANGELOG.md b/sdk/identity/azure-identity/CHANGELOG.md index e18eca60e91c..e4c4ca143879 100644 --- a/sdk/identity/azure-identity/CHANGELOG.md +++ b/sdk/identity/azure-identity/CHANGELOG.md @@ -1,7 +1,7 @@ # Release History -## 1.1.0-beta.1 (Unreleased) - +## 1.0.9 (2020-07-17) +- Upgraded `msal4j` dependency to 1.6.1 ## 1.0.8 (2020-07-06) - Upgraded `azure-core` dependency to 1.6.0 diff --git a/sdk/identity/azure-identity/README.md b/sdk/identity/azure-identity/README.md index b45f08c3a943..16571578c405 100644 --- a/sdk/identity/azure-identity/README.md +++ b/sdk/identity/azure-identity/README.md @@ -11,32 +11,8 @@ The Azure Identity library provides Azure Active Directory token authentication [Source code][source] | [API reference documentation][javadoc] | [Azure Active Directory documentation][aad_doc] -## Table of contents -- [Getting started](#getting-started) - - [Adding the package to your project](#adding-the-package-to-your-project) - - [Prerequisites](#prerequisites) - - [Creating a Service Principal with the Azure CLI](#creating-a-service-principal-with-the-azure-cli) - - [Enable applications for device code flow](#enable-applications-for-device-code-flow) - - [Enable applications for interactive browser oauth 2 flow](#enable-applications-for-interactive-browser-oauth-2-flow) - - [Enable applications for oauth 2 auth code flow](#enable-applications-for-oauth-2-auth-code-flow) - - [Enable applications for shared token cache credential](#enable-applications-for-shared-token-cache-credential) - - [Key concepts](#key-concepts) - - [Credentials](#credentials) - - [DefaultAzureCredential](#defaultazurecredential) - - [Environment variables](#environment-variables) -- [Examples](#examples) - - [Authenticating with `DefaultAzureCredential`](#authenticating-with-defaultazurecredential) - - [Authenticating a service principal with a client secret](#authenticating-a-service-principal-with-a-client-secret) - - [Authenticating a user account with device code flow](#authenticating-a-user-account-with-device-code-flow) - - [Authenticating a user account with username and password](#authenticating-a-user-account-with-username-and-password) - - [Authenticating a user account with auth code flow](#authenticating-a-user-account-with-auth-code-flow) - - [Chaining credentials](#chaining-credentials) -- [Troubleshooting](#troubleshooting) -- [Next steps](#next-steps) -- [Contributing](#contributing) - ## Getting started -### Adding the package to your project +### Include the package Maven dependency for Azure Secret Client library. Add it to your project's pom file. @@ -148,6 +124,14 @@ principal authentication with these environment variables: ## Examples +### Table of contents + - [Authenticating with `DefaultAzureCredential`](#authenticating-with-defaultazurecredential) + - [Authenticating a service principal with a client secret](#authenticating-a-service-principal-with-a-client-secret) + - [Authenticating a user account with device code flow](#authenticating-a-user-account-with-device-code-flow) + - [Authenticating a user account with username and password](#authenticating-a-user-account-with-username-and-password) + - [Authenticating a user account with auth code flow](#authenticating-a-user-account-with-auth-code-flow) + - [Chaining credentials](#chaining-credentials) + ### Authenticating with `DefaultAzureCredential` This example demonstrates authenticating the `SecretClient` from the [azure-security-keyvault-secrets][secrets_client_library] client library using the `DefaultAzureCredential`. There's also [a compilable sample](../../keyvault/azure-security-keyvault-secrets/src/samples/java/com/azure/security/keyvault/secrets/IdentitySamples.java) to create a Key Vault secret client you can copy-paste. diff --git a/sdk/identity/azure-identity/pom.xml b/sdk/identity/azure-identity/pom.xml index ebb2c286141a..4c3c5ce63fd1 100644 --- a/sdk/identity/azure-identity/pom.xml +++ b/sdk/identity/azure-identity/pom.xml @@ -6,8 +6,7 @@ com.azure azure-identity - 1.1.0-beta.1 - + 1.0.9 Microsoft Azure client library for Identity This module contains client library for Microsoft Azure Identity. https://github.com/Azure/azure-sdk-for-java @@ -48,7 +47,7 @@ com.azure:* - com.microsoft.azure:msal4j:[0.5.0-preview] + com.microsoft.azure:msal4j:[1.6.1] com.nimbusds:oauth2-oidc-sdk:[6.14] net.java.dev.jna:jna-platform:[5.4.0] org.nanohttpd:nanohttpd:[2.3.1] @@ -70,7 +69,7 @@ com.microsoft.azure msal4j - 0.5.0-preview + 1.6.1 com.nimbusds @@ -82,7 +81,6 @@ nanohttpd 2.3.1 - junit junit diff --git a/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/IdentityClient.java b/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/IdentityClient.java index 33cad876b36b..5523b8d6a42d 100644 --- a/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/IdentityClient.java +++ b/sdk/identity/azure-identity/src/main/java/com/azure/identity/implementation/IdentityClient.java @@ -110,7 +110,7 @@ public Mono authenticateWithClientSecret(String clientSecret, Token String authorityUrl = options.getAuthorityHost().replaceAll("/+$", "") + "/" + tenantId; try { ConfidentialClientApplication.Builder applicationBuilder = - ConfidentialClientApplication.builder(clientId, ClientCredentialFactory.create(clientSecret)) + ConfidentialClientApplication.builder(clientId, ClientCredentialFactory.createFromSecret(clientSecret)) .authority(authorityUrl); if (options.getProxyOptions() != null) { applicationBuilder.proxy(proxyOptionsToJavaNetProxy(options.getProxyOptions())); @@ -139,8 +139,8 @@ public Mono authenticateWithPfxCertificate(String pfxCertificatePat String authorityUrl = options.getAuthorityHost().replaceAll("/+$", "") + "/" + tenantId; try { ConfidentialClientApplication.Builder applicationBuilder = - ConfidentialClientApplication.builder(clientId, - ClientCredentialFactory.create(new FileInputStream(pfxCertificatePath), pfxCertificatePassword)) + ConfidentialClientApplication.builder(clientId, ClientCredentialFactory.createFromCertificate( + new FileInputStream(pfxCertificatePath), pfxCertificatePassword)) .authority(authorityUrl); if (options.getProxyOptions() != null) { applicationBuilder.proxy(proxyOptionsToJavaNetProxy(options.getProxyOptions())); @@ -174,7 +174,8 @@ public Mono authenticateWithPemCertificate(String pemCertificatePat byte[] pemCertificateBytes = Files.readAllBytes(Paths.get(pemCertificatePath)); ConfidentialClientApplication.Builder applicationBuilder = ConfidentialClientApplication.builder(clientId, - ClientCredentialFactory.create(CertificateUtil.privateKeyFromPem(pemCertificateBytes), + ClientCredentialFactory.createFromCertificate( + CertificateUtil.privateKeyFromPem(pemCertificateBytes), CertificateUtil.publicKeyFromPem(pemCertificateBytes))).authority(authorityUrl); if (options.getProxyOptions() != null) { applicationBuilder.proxy(proxyOptionsToJavaNetProxy(options.getProxyOptions())); diff --git a/sdk/identity/azure-identity/src/test/java/com/azure/identity/implementation/IdentityClientTests.java b/sdk/identity/azure-identity/src/test/java/com/azure/identity/implementation/IdentityClientTests.java index 9544bef34c8c..d5aec209d1e2 100644 --- a/sdk/identity/azure-identity/src/test/java/com/azure/identity/implementation/IdentityClientTests.java +++ b/sdk/identity/azure-identity/src/test/java/com/azure/identity/implementation/IdentityClientTests.java @@ -6,11 +6,11 @@ import com.azure.core.credential.AccessToken; import com.azure.core.credential.TokenRequestContext; import com.azure.identity.util.TestUtils; -import com.microsoft.aad.msal4j.AsymmetricKeyCredential; import com.microsoft.aad.msal4j.ClientCredentialParameters; -import com.microsoft.aad.msal4j.ClientSecret; import com.microsoft.aad.msal4j.ConfidentialClientApplication; import com.microsoft.aad.msal4j.DeviceCodeFlowParameters; +import com.microsoft.aad.msal4j.IClientCredential; +import com.microsoft.aad.msal4j.IClientSecret; import com.microsoft.aad.msal4j.MsalServiceException; import com.microsoft.aad.msal4j.PublicClientApplication; import org.junit.Assert; @@ -156,7 +156,7 @@ private void mockForClientSecret(String secret, TokenRequestContext request, Str when(builder.authority(any())).thenReturn(builder); whenNew(ConfidentialClientApplication.Builder.class).withAnyArguments().thenAnswer(invocation -> { String cid = (String) invocation.getArguments()[0]; - ClientSecret clientSecret = (ClientSecret) invocation.getArguments()[1]; + IClientSecret clientSecret = (IClientSecret) invocation.getArguments()[1]; if (!clientId.equals(cid)) { throw new MsalServiceException("Invalid clientId", "InvalidClientId"); } @@ -184,11 +184,11 @@ private void mockForClientCertificate(TokenRequestContext request, String access when(builder.authority(any())).thenReturn(builder); whenNew(ConfidentialClientApplication.Builder.class).withAnyArguments().thenAnswer(invocation -> { String cid = (String) invocation.getArguments()[0]; - AsymmetricKeyCredential keyCredential = (AsymmetricKeyCredential) invocation.getArguments()[1]; + IClientCredential keyCredential = (IClientCredential) invocation.getArguments()[1]; if (!clientId.equals(cid)) { throw new MsalServiceException("Invalid clientId", "InvalidClientId"); } - if (keyCredential == null || keyCredential.key() == null) { + if (keyCredential == null) { throw new MsalServiceException("Invalid clientCertificate", "InvalidClientCertificate"); } return builder; diff --git a/sdk/identity/azure-identity/src/test/java/com/azure/identity/implementation/msalextensions/CrossProgramVSTest.java b/sdk/identity/azure-identity/src/test/java/com/azure/identity/implementation/msalextensions/CrossProgramVSTest.java index 2af976acc872..e6dd0adefec1 100644 --- a/sdk/identity/azure-identity/src/test/java/com/azure/identity/implementation/msalextensions/CrossProgramVSTest.java +++ b/sdk/identity/azure-identity/src/test/java/com/azure/identity/implementation/msalextensions/CrossProgramVSTest.java @@ -3,9 +3,10 @@ package com.azure.identity.implementation.msalextensions; +import com.azure.core.util.serializer.JacksonAdapter; +import com.azure.core.util.serializer.SerializerAdapter; +import com.azure.core.util.serializer.SerializerEncoding; import com.azure.identity.implementation.msalextensions.cachepersister.CachePersister; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; import com.microsoft.aad.msal4j.ClientCredentialFactory; import com.microsoft.aad.msal4j.ClientCredentialParameters; import com.microsoft.aad.msal4j.ConfidentialClientApplication; @@ -15,6 +16,7 @@ import org.junit.Test; import java.util.Collections; +import java.util.Map; import java.util.concurrent.CompletableFuture; /* @@ -36,6 +38,8 @@ public class CrossProgramVSTest { private int count = 0; + private final SerializerAdapter serializerAdapter = JacksonAdapter.createDefaultSerializerAdapter(); + @Before public void setup() throws Exception { org.junit.Assume.assumeTrue("Skipping these tests until we mock or record it", false); @@ -44,7 +48,7 @@ public void setup() throws Exception { accessAspect = new PersistentTokenCacheAccessAspect(); confApp = ConfidentialClientApplication.builder(TestConfiguration.CONFIDENTIAL_CLIENT_ID, - ClientCredentialFactory.create(TestConfiguration.CONFIDENTIAL_CLIENT_SECRET)) + ClientCredentialFactory.createFromSecret(TestConfiguration.CONFIDENTIAL_CLIENT_SECRET)) .authority(TestConfiguration.TENANT_SPECIFIC_AUTHORITY) .setTokenCacheAccessAspect(accessAspect) .build(); @@ -55,29 +59,29 @@ public void setup() throws Exception { } @Test - public void readCacheAfterVSAzureLogin() { + public void readCacheAfterVSAzureLogin() throws Exception { byte[] currJsonBytes = cachePersister.readCache(); String currJson = new String(currJsonBytes); - JsonObject jsonObj = new JsonParser().parse(currJson).getAsJsonObject(); + Map jsonObj = serializerAdapter.deserialize(currJson, Map.class, SerializerEncoding.JSON); - Assert.assertTrue(jsonObj.has("AccessToken")); - Assert.assertTrue(jsonObj.has("RefreshToken")); - Assert.assertTrue(jsonObj.has("IdToken")); - Assert.assertTrue(jsonObj.has("Account")); - Assert.assertTrue(jsonObj.has("AppMetadata")); + Assert.assertTrue(jsonObj.containsKey("AccessToken")); + Assert.assertTrue(jsonObj.containsKey("RefreshToken")); + Assert.assertTrue(jsonObj.containsKey("IdToken")); + Assert.assertTrue(jsonObj.containsKey("Account")); + Assert.assertTrue(jsonObj.containsKey("AppMetadata")); System.out.println(currJson); - - count = jsonObj.get("AccessToken").getAsJsonObject().keySet().size(); } @Test - public void writeToSameCacheFileAfterVSAzureLogin() { + public void writeToSameCacheFileAfterVSAzureLogin() throws Exception { String currJson = new String(cachePersister.readCache()); - JsonObject jsonObj = new JsonParser().parse(currJson).getAsJsonObject(); + Map jsonObj = serializerAdapter.deserialize(currJson, Map.class, SerializerEncoding.JSON); + Map accessTokenObj = serializerAdapter.deserialize( + serializerAdapter.serialize(jsonObj.get("AccessToken"), SerializerEncoding.JSON), Map.class, SerializerEncoding.JSON); - int set = jsonObj.get("AccessToken").getAsJsonObject().keySet().size(); + int set = accessTokenObj.size(); CompletableFuture result = confApp.acquireToken(confParameters); result.handle((res, ex) -> { @@ -90,9 +94,11 @@ public void writeToSameCacheFileAfterVSAzureLogin() { }).join(); currJson = new String(cachePersister.readCache()); - jsonObj = new JsonParser().parse(currJson).getAsJsonObject(); + jsonObj = serializerAdapter.deserialize(currJson, Map.class, SerializerEncoding.JSON); + accessTokenObj = serializerAdapter.deserialize( + serializerAdapter.serialize(jsonObj.get("AccessToken"), SerializerEncoding.JSON), Map.class, SerializerEncoding.JSON); - int newSet = jsonObj.get("AccessToken").getAsJsonObject().keySet().size(); + int newSet = accessTokenObj.size(); Assert.assertEquals(newSet, set + 1); count++; @@ -101,24 +107,27 @@ public void writeToSameCacheFileAfterVSAzureLogin() { } @Test - public void countCache() { + public void countCache() throws Exception { byte[] currJsonBytes = cachePersister.readCache(); String currJson = new String(currJsonBytes); - - JsonObject jsonObj = new JsonParser().parse(currJson).getAsJsonObject(); - int newSet = jsonObj.get("AccessToken").getAsJsonObject().keySet().size(); + Map jsonObj = serializerAdapter.deserialize(currJson, Map.class, SerializerEncoding.JSON); + Map accessTokenObj = serializerAdapter.deserialize( + serializerAdapter.serialize(jsonObj.get("AccessToken"), SerializerEncoding.JSON), Map.class, SerializerEncoding.JSON); + int newSet = accessTokenObj.size(); System.out.println(newSet); } @Test - public void readCacheAfterPowershellAzureLogin() { + public void readCacheAfterPowershellAzureLogin() throws Exception { byte[] currJsonBytes = cachePersister.readCache(); String currJson = new String(currJsonBytes); - JsonObject jsonObj = new JsonParser().parse(currJson).getAsJsonObject(); + Map jsonObj = serializerAdapter.deserialize(currJson, Map.class, SerializerEncoding.JSON); System.out.println(currJson); - int newSet = jsonObj.get("AccessToken").getAsJsonObject().keySet().size(); + Map accessTokenObj = serializerAdapter.deserialize( + serializerAdapter.serialize(jsonObj.get("AccessToken"), SerializerEncoding.JSON), Map.class, SerializerEncoding.JSON); + int newSet = accessTokenObj.size(); Assert.assertEquals(newSet, 6); count++; diff --git a/sdk/identity/azure-identity/src/test/java/com/azure/identity/implementation/msalextensions/MultithreadedTokenCacheTest.java b/sdk/identity/azure-identity/src/test/java/com/azure/identity/implementation/msalextensions/MultithreadedTokenCacheTest.java index 9d347ae8edaf..01ed02b6c032 100644 --- a/sdk/identity/azure-identity/src/test/java/com/azure/identity/implementation/msalextensions/MultithreadedTokenCacheTest.java +++ b/sdk/identity/azure-identity/src/test/java/com/azure/identity/implementation/msalextensions/MultithreadedTokenCacheTest.java @@ -3,20 +3,29 @@ package com.azure.identity.implementation.msalextensions; +import com.azure.core.util.serializer.JacksonAdapter; +import com.azure.core.util.serializer.SerializerAdapter; +import com.azure.core.util.serializer.SerializerEncoding; import com.azure.identity.implementation.msalextensions.cachepersister.CachePersister; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.microsoft.aad.msal4j.*; +import com.microsoft.aad.msal4j.ClientCredentialFactory; +import com.microsoft.aad.msal4j.ClientCredentialParameters; +import com.microsoft.aad.msal4j.ConfidentialClientApplication; +import com.microsoft.aad.msal4j.DeviceCode; +import com.microsoft.aad.msal4j.DeviceCodeFlowParameters; +import com.microsoft.aad.msal4j.IAuthenticationResult; +import com.microsoft.aad.msal4j.PublicClientApplication; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import java.util.Collections; +import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.function.Consumer; public class MultithreadedTokenCacheTest { + private final SerializerAdapter serializerAdapter = JacksonAdapter.createDefaultSerializerAdapter(); private PersistentTokenCacheAccessAspect accessAspect; private CachePersister cachePersister; @@ -38,13 +47,13 @@ public void setup() throws Exception { accessAspect = new PersistentTokenCacheAccessAspect(cachePersister); confApp = ConfidentialClientApplication.builder(TestConfiguration.CONFIDENTIAL_CLIENT_ID, - ClientCredentialFactory.create(TestConfiguration.CONFIDENTIAL_CLIENT_SECRET)) + ClientCredentialFactory.createFromSecret(TestConfiguration.CONFIDENTIAL_CLIENT_SECRET)) .authority(TestConfiguration.TENANT_SPECIFIC_AUTHORITY) .setTokenCacheAccessAspect(accessAspect) .build(); confApp2 = ConfidentialClientApplication.builder(TestConfiguration.CONFIDENTIAL_CLIENT_ID_2, - ClientCredentialFactory.create(TestConfiguration.CONFIDENTIAL_CLIENT_SECRET_2)) + ClientCredentialFactory.createFromSecret(TestConfiguration.CONFIDENTIAL_CLIENT_SECRET_2)) .authority(TestConfiguration.TENANT_SPECIFIC_AUTHORITY) .setTokenCacheAccessAspect(accessAspect) .build(); @@ -75,7 +84,7 @@ public void cleanup() { } @Test - public void twoThreadsWritingTokens() { + public void twoThreadsWritingTokens() throws Exception { ConcurrentClient a = new ConcurrentClient("conf"); ConcurrentClient b = new ConcurrentClient("pub"); @@ -90,19 +99,30 @@ public void twoThreadsWritingTokens() { byte[] currJsonBytes = cachePersister.readCache(); String currJson = new String(currJsonBytes); - JsonObject jsonObj = new JsonParser().parse(currJson).getAsJsonObject(); - - Assert.assertTrue(jsonObj.get("AccessToken").getAsJsonObject().keySet().size() == 2); - Assert.assertTrue(jsonObj.get("RefreshToken").getAsJsonObject().keySet().size() == 1); - Assert.assertTrue(jsonObj.get("IdToken").getAsJsonObject().keySet().size() == 1); - Assert.assertTrue(jsonObj.get("Account").getAsJsonObject().keySet().size() == 1); - Assert.assertTrue(jsonObj.get("AppMetadata").getAsJsonObject().keySet().size() == 1); + Map jsonObj = serializerAdapter.deserialize(currJson, Map.class, SerializerEncoding.JSON); + Map accessTokenObj = serializerAdapter.deserialize( + serializerAdapter.serialize(jsonObj.get("AccessToken"), SerializerEncoding.JSON), Map.class, SerializerEncoding.JSON); + Map refreshTokenObj = serializerAdapter.deserialize( + serializerAdapter.serialize(jsonObj.get("RefreshToken"), SerializerEncoding.JSON), Map.class, SerializerEncoding.JSON); + Map idTokenObj = serializerAdapter.deserialize( + serializerAdapter.serialize(jsonObj.get("IdToken"), SerializerEncoding.JSON), Map.class, SerializerEncoding.JSON); + Map accountObj = serializerAdapter.deserialize( + serializerAdapter.serialize(jsonObj.get("Account"), SerializerEncoding.JSON), Map.class, SerializerEncoding.JSON); + Map appMetadataObj = serializerAdapter.deserialize( + serializerAdapter.serialize(jsonObj.get("AppMetadata"), SerializerEncoding.JSON), Map.class, SerializerEncoding.JSON); + + + Assert.assertEquals(2, accessTokenObj.size()); + Assert.assertEquals(1, refreshTokenObj.size()); + Assert.assertEquals(1, idTokenObj.size()); + Assert.assertEquals(1, accountObj.size()); + Assert.assertEquals(1, appMetadataObj.size()); accessAspect.deleteCache(); } @Test - public void tenThreadsWritingSameConfTokens() { + public void tenThreadsWritingSameConfTokens() throws Exception { ConcurrentClient a = new ConcurrentClient("conf"); ConcurrentClient b = new ConcurrentClient("conf"); @@ -134,16 +154,27 @@ public void tenThreadsWritingSameConfTokens() { byte[] currJsonBytes = cachePersister.readCache(); String currJson = new String(currJsonBytes); - JsonObject jsonObj = new JsonParser().parse(currJson).getAsJsonObject(); + Map jsonObj = serializerAdapter.deserialize(currJson, Map.class, SerializerEncoding.JSON); + Map accessTokenObj = serializerAdapter.deserialize( + serializerAdapter.serialize(jsonObj.get("AccessToken"), SerializerEncoding.JSON), Map.class, SerializerEncoding.JSON); + + System.out.println("keys: " + accessTokenObj.size()); + Map refreshTokenObj = serializerAdapter.deserialize( + serializerAdapter.serialize(jsonObj.get("RefreshToken"), SerializerEncoding.JSON), Map.class, SerializerEncoding.JSON); + Map idTokenObj = serializerAdapter.deserialize( + serializerAdapter.serialize(jsonObj.get("IdToken"), SerializerEncoding.JSON), Map.class, SerializerEncoding.JSON); + Map accountObj = serializerAdapter.deserialize( + serializerAdapter.serialize(jsonObj.get("Account"), SerializerEncoding.JSON), Map.class, SerializerEncoding.JSON); + Map appMetadataObj = serializerAdapter.deserialize( + serializerAdapter.serialize(jsonObj.get("AppMetadata"), SerializerEncoding.JSON), Map.class, SerializerEncoding.JSON); - System.out.println("keys: " + jsonObj.get("AccessToken").getAsJsonObject().keySet().size()); - Assert.assertTrue(jsonObj.get("AccessToken").getAsJsonObject().keySet().size() == 1); - Assert.assertTrue(jsonObj.get("RefreshToken").getAsJsonObject().keySet().size() == 0); - Assert.assertTrue(jsonObj.get("IdToken").getAsJsonObject().keySet().size() == 0); - Assert.assertTrue(jsonObj.get("Account").getAsJsonObject().keySet().size() == 0); - Assert.assertTrue(jsonObj.get("AppMetadata").getAsJsonObject().keySet().size() == 0); + Assert.assertEquals(1, accessTokenObj.size()); + Assert.assertEquals(0, refreshTokenObj.size()); + Assert.assertEquals(0, idTokenObj.size()); + Assert.assertEquals(0, accountObj.size()); + Assert.assertEquals(0, appMetadataObj.size()); accessAspect.deleteCache(); } diff --git a/sdk/identity/azure-identity/src/test/java/com/azure/identity/implementation/msalextensions/PersistentTokenCacheAccessAspectTest.java b/sdk/identity/azure-identity/src/test/java/com/azure/identity/implementation/msalextensions/PersistentTokenCacheAccessAspectTest.java index 2b78b6daae7b..bcdc0cde978d 100644 --- a/sdk/identity/azure-identity/src/test/java/com/azure/identity/implementation/msalextensions/PersistentTokenCacheAccessAspectTest.java +++ b/sdk/identity/azure-identity/src/test/java/com/azure/identity/implementation/msalextensions/PersistentTokenCacheAccessAspectTest.java @@ -3,20 +3,29 @@ package com.azure.identity.implementation.msalextensions; +import com.azure.core.util.serializer.JacksonAdapter; +import com.azure.core.util.serializer.SerializerAdapter; +import com.azure.core.util.serializer.SerializerEncoding; import com.azure.identity.implementation.msalextensions.cachepersister.CachePersister; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.microsoft.aad.msal4j.*; +import com.microsoft.aad.msal4j.ClientCredentialFactory; +import com.microsoft.aad.msal4j.ClientCredentialParameters; +import com.microsoft.aad.msal4j.ConfidentialClientApplication; +import com.microsoft.aad.msal4j.DeviceCode; +import com.microsoft.aad.msal4j.DeviceCodeFlowParameters; +import com.microsoft.aad.msal4j.IAuthenticationResult; +import com.microsoft.aad.msal4j.PublicClientApplication; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; import java.util.Collections; +import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.function.Consumer; public class PersistentTokenCacheAccessAspectTest { + private final SerializerAdapter serializerAdapter = JacksonAdapter.createDefaultSerializerAdapter(); private PersistentTokenCacheAccessAspect accessAspect; private CachePersister cachePersister; @@ -42,13 +51,13 @@ public void setup() throws Exception { }; confApp = ConfidentialClientApplication.builder(TestConfiguration.CONFIDENTIAL_CLIENT_ID, - ClientCredentialFactory.create(TestConfiguration.CONFIDENTIAL_CLIENT_SECRET)) + ClientCredentialFactory.createFromSecret(TestConfiguration.CONFIDENTIAL_CLIENT_SECRET)) .authority(TestConfiguration.TENANT_SPECIFIC_AUTHORITY) .setTokenCacheAccessAspect(accessAspect) .build(); confApp2 = ConfidentialClientApplication.builder(TestConfiguration.CONFIDENTIAL_CLIENT_ID_2, - ClientCredentialFactory.create(TestConfiguration.CONFIDENTIAL_CLIENT_SECRET_2)) + ClientCredentialFactory.createFromSecret(TestConfiguration.CONFIDENTIAL_CLIENT_SECRET_2)) .authority(TestConfiguration.TENANT_SPECIFIC_AUTHORITY) .setTokenCacheAccessAspect(accessAspect) .build(); @@ -76,7 +85,7 @@ public void cleanup() { } @Test - public void checkIfWritesToFileFirstTimeConfidentialClient() { + public void checkIfWritesToFileFirstTimeConfidentialClient() throws Exception { CompletableFuture result = confApp.acquireToken(confParameters); @@ -92,23 +101,24 @@ public void checkIfWritesToFileFirstTimeConfidentialClient() { byte[] currJsonBytes = cachePersister.readCache(); String currJson = new String(currJsonBytes); - JsonObject jsonObj = new JsonParser().parse(currJson).getAsJsonObject(); + Map jsonObj = serializerAdapter.deserialize(currJson, Map.class, SerializerEncoding.JSON); - Assert.assertTrue(jsonObj.has("AccessToken")); - Assert.assertTrue(jsonObj.has("RefreshToken")); - Assert.assertTrue(jsonObj.has("IdToken")); - Assert.assertTrue(jsonObj.has("Account")); - Assert.assertTrue(jsonObj.has("AppMetadata")); + Assert.assertTrue(jsonObj.containsKey("AccessToken")); + Assert.assertTrue(jsonObj.containsKey("RefreshToken")); + Assert.assertTrue(jsonObj.containsKey("IdToken")); + Assert.assertTrue(jsonObj.containsKey("Account")); + Assert.assertTrue(jsonObj.containsKey("AppMetadata")); - int set = jsonObj.get("AccessToken").getAsJsonObject().keySet().size(); + Map accessTokenObj = serializerAdapter.deserialize( + serializerAdapter.serialize(jsonObj.get("AccessToken"), SerializerEncoding.JSON), Map.class, SerializerEncoding.JSON); - Assert.assertEquals(set, 1); + Assert.assertEquals(1, accessTokenObj.size()); accessAspect.deleteCache(); } @Test - public void checkIfWritesToFileFirstTimePublicClient() { + public void checkIfWritesToFileFirstTimePublicClient() throws Exception { CompletableFuture result = pubApp.acquireToken( pubParameters); @@ -125,15 +135,18 @@ public void checkIfWritesToFileFirstTimePublicClient() { byte[] currJsonBytes = cachePersister.readCache(); String currJson = new String(currJsonBytes); - JsonObject jsonObj = new JsonParser().parse(currJson).getAsJsonObject(); + Map jsonObj = serializerAdapter.deserialize(currJson, Map.class, SerializerEncoding.JSON); - Assert.assertTrue(jsonObj.has("AccessToken")); - Assert.assertTrue(jsonObj.has("RefreshToken")); - Assert.assertTrue(jsonObj.has("IdToken")); - Assert.assertTrue(jsonObj.has("Account")); - Assert.assertTrue(jsonObj.has("AppMetadata")); + Assert.assertTrue(jsonObj.containsKey("AccessToken")); + Assert.assertTrue(jsonObj.containsKey("RefreshToken")); + Assert.assertTrue(jsonObj.containsKey("IdToken")); + Assert.assertTrue(jsonObj.containsKey("Account")); + Assert.assertTrue(jsonObj.containsKey("AppMetadata")); - Assert.assertTrue(jsonObj.get("AccessToken").getAsJsonObject().keySet().size() == 1); + Map accessTokenObj = serializerAdapter.deserialize( + serializerAdapter.serialize(jsonObj.get("AccessToken"), SerializerEncoding.JSON), Map.class, SerializerEncoding.JSON); + + Assert.assertEquals(1, accessTokenObj.size()); accessAspect.deleteCache(); } @@ -160,7 +173,7 @@ public void addsAccountToListPubClient() { } @Test - public void writesTwoTokensToCache() { + public void writesTwoTokensToCache() throws Exception { CompletableFuture result = pubApp.acquireToken( pubParameters); @@ -188,19 +201,30 @@ public void writesTwoTokensToCache() { byte[] currJsonBytes = cachePersister.readCache(); String currJson = new String(currJsonBytes); - JsonObject jsonObj = new JsonParser().parse(currJson).getAsJsonObject(); - - Assert.assertTrue(jsonObj.get("AccessToken").getAsJsonObject().keySet().size() == 2); - Assert.assertTrue(jsonObj.get("RefreshToken").getAsJsonObject().keySet().size() == 1); - Assert.assertTrue(jsonObj.get("IdToken").getAsJsonObject().keySet().size() == 1); - Assert.assertTrue(jsonObj.get("Account").getAsJsonObject().keySet().size() == 1); - Assert.assertTrue(jsonObj.get("AppMetadata").getAsJsonObject().keySet().size() == 1); + Map jsonObj = serializerAdapter.deserialize(currJson, Map.class, SerializerEncoding.JSON); + Map accessTokenObj = serializerAdapter.deserialize( + serializerAdapter.serialize(jsonObj.get("AccessToken"), SerializerEncoding.JSON), Map.class, SerializerEncoding.JSON); + Map refreshTokenObj = serializerAdapter.deserialize( + serializerAdapter.serialize(jsonObj.get("RefreshToken"), SerializerEncoding.JSON), Map.class, SerializerEncoding.JSON); + Map idTokenObj = serializerAdapter.deserialize( + serializerAdapter.serialize(jsonObj.get("IdToken"), SerializerEncoding.JSON), Map.class, SerializerEncoding.JSON); + Map accountObj = serializerAdapter.deserialize( + serializerAdapter.serialize(jsonObj.get("Account"), SerializerEncoding.JSON), Map.class, SerializerEncoding.JSON); + Map appMetadataObj = serializerAdapter.deserialize( + serializerAdapter.serialize(jsonObj.get("AppMetadata"), SerializerEncoding.JSON), Map.class, SerializerEncoding.JSON); + + + Assert.assertEquals(2, accessTokenObj.size()); + Assert.assertEquals(1, refreshTokenObj.size()); + Assert.assertEquals(1, idTokenObj.size()); + Assert.assertEquals(1, accountObj.size()); + Assert.assertEquals(1, appMetadataObj.size()); accessAspect.deleteCache(); } @Test - public void writesReadsMultipleTokensToCache() { + public void writesReadsMultipleTokensToCache() throws Exception { CompletableFuture result = pubApp.acquireToken( pubParameters); @@ -238,13 +262,24 @@ public void writesReadsMultipleTokensToCache() { byte[] currJsonBytes = cachePersister.readCache(); String currJson = new String(currJsonBytes); - JsonObject jsonObj = new JsonParser().parse(currJson).getAsJsonObject(); - - Assert.assertTrue(jsonObj.get("AccessToken").getAsJsonObject().keySet().size() == 3); - Assert.assertTrue(jsonObj.get("RefreshToken").getAsJsonObject().keySet().size() == 1); - Assert.assertTrue(jsonObj.get("IdToken").getAsJsonObject().keySet().size() == 1); - Assert.assertTrue(jsonObj.get("Account").getAsJsonObject().keySet().size() == 1); - Assert.assertTrue(jsonObj.get("AppMetadata").getAsJsonObject().keySet().size() == 1); + Map jsonObj = serializerAdapter.deserialize(currJson, Map.class, SerializerEncoding.JSON); + Map accessTokenObj = serializerAdapter.deserialize( + serializerAdapter.serialize(jsonObj.get("AccessToken"), SerializerEncoding.JSON), Map.class, SerializerEncoding.JSON); + Map refreshTokenObj = serializerAdapter.deserialize( + serializerAdapter.serialize(jsonObj.get("RefreshToken"), SerializerEncoding.JSON), Map.class, SerializerEncoding.JSON); + Map idTokenObj = serializerAdapter.deserialize( + serializerAdapter.serialize(jsonObj.get("IdToken"), SerializerEncoding.JSON), Map.class, SerializerEncoding.JSON); + Map accountObj = serializerAdapter.deserialize( + serializerAdapter.serialize(jsonObj.get("Account"), SerializerEncoding.JSON), Map.class, SerializerEncoding.JSON); + Map appMetadataObj = serializerAdapter.deserialize( + serializerAdapter.serialize(jsonObj.get("AppMetadata"), SerializerEncoding.JSON), Map.class, SerializerEncoding.JSON); + + + Assert.assertEquals(3, accessTokenObj.size()); + Assert.assertEquals(1, refreshTokenObj.size()); + Assert.assertEquals(1, idTokenObj.size()); + Assert.assertEquals(1, accountObj.size()); + Assert.assertEquals(1, appMetadataObj.size()); accessAspect.deleteCache(); } diff --git a/sdk/identity/azure-identity/src/test/java/com/azure/identity/util/TestUtils.java b/sdk/identity/azure-identity/src/test/java/com/azure/identity/util/TestUtils.java index fdd42968b9a7..78545f83ab39 100644 --- a/sdk/identity/azure-identity/src/test/java/com/azure/identity/util/TestUtils.java +++ b/sdk/identity/azure-identity/src/test/java/com/azure/identity/util/TestUtils.java @@ -5,7 +5,6 @@ import com.azure.core.credential.AccessToken; import com.azure.identity.implementation.MsalToken; -import com.microsoft.aad.msal4j.Account; import com.microsoft.aad.msal4j.IAccount; import com.microsoft.aad.msal4j.IAuthenticationResult; import reactor.core.publisher.Mono; @@ -39,7 +38,22 @@ public String idToken() { @Override public IAccount account() { - return new Account(UUID.randomUUID().toString(), "http://login.microsoftonline.com", "testuser"); + return new IAccount() { + @Override + public String homeAccountId() { + return UUID.randomUUID().toString(); + } + + @Override + public String environment() { + return "http://login.microsoftonline.com"; + } + + @Override + public String username() { + return "testuser"; + } + }; } @Override diff --git a/sdk/spring/azure-spring-boot-starter-active-directory/pom.xml b/sdk/spring/azure-spring-boot-starter-active-directory/pom.xml index 22852e82eb4e..424f564150c9 100644 --- a/sdk/spring/azure-spring-boot-starter-active-directory/pom.xml +++ b/sdk/spring/azure-spring-boot-starter-active-directory/pom.xml @@ -58,7 +58,7 @@ com.microsoft.azure msal4j - 0.5.0-preview + 1.6.1 com.nimbusds @@ -84,7 +84,7 @@ com.microsoft.azure:azure-spring-boot:[2.3.3-beta.1] --> com.fasterxml.jackson.core:jackson-databind:[2.10.1] - com.microsoft.azure:msal4j:[0.5.0-preview] + com.microsoft.azure:msal4j:[1.6.1] com.nimbusds:nimbus-jose-jwt:[7.9] org.springframework:spring-web:[5.2.6.RELEASE] org.springframework.boot:spring-boot-starter:[2.3.0.RELEASE] diff --git a/sdk/spring/azure-spring-boot/pom.xml b/sdk/spring/azure-spring-boot/pom.xml index 18f0dc0f75d0..7db70abf6c89 100644 --- a/sdk/spring/azure-spring-boot/pom.xml +++ b/sdk/spring/azure-spring-boot/pom.xml @@ -159,14 +159,14 @@ com.microsoft.azure msal4j - 0.5.0-preview + 1.6.1 true com.azure azure-identity - 1.0.8 + 1.0.9 @@ -268,7 +268,7 @@ com.google.code.findbugs:jsr305:[3.0.2] net.minidev:json-smart:[2.3] com.microsoft.azure:azure-servicebus-jms:[0.0.2] - com.microsoft.azure:msal4j:[0.5.0-preview] + com.microsoft.azure:msal4j:[1.6.1] com.microsoft.azure:spring-data-cosmosdb:[2.3.0] com.microsoft.spring.data.gremlin:spring-data-gremlin:[2.2.3] com.nimbusds:nimbus-jose-jwt:[7.9] diff --git a/sdk/spring/azure-spring-boot/src/main/java/com/microsoft/azure/spring/autoconfigure/aad/AzureADGraphClient.java b/sdk/spring/azure-spring-boot/src/main/java/com/microsoft/azure/spring/autoconfigure/aad/AzureADGraphClient.java index 107f2f483b6a..500d96d3aa29 100644 --- a/sdk/spring/azure-spring-boot/src/main/java/com/microsoft/azure/spring/autoconfigure/aad/AzureADGraphClient.java +++ b/sdk/spring/azure-spring-boot/src/main/java/com/microsoft/azure/spring/autoconfigure/aad/AzureADGraphClient.java @@ -195,7 +195,7 @@ private boolean isValidUserGroupToGrantAuthority(final UserGroup group) { public IAuthenticationResult acquireTokenForGraphApi(String idToken, String tenantId) throws ServiceUnavailableException { - final IClientCredential clientCredential = ClientCredentialFactory.create(clientSecret); + final IClientCredential clientCredential = ClientCredentialFactory.createFromSecret(clientSecret); final UserAssertion assertion = new UserAssertion(idToken); IAuthenticationResult result = null; diff --git a/sdk/storage/azure-storage-blob-changefeed/src/test/java/com/azure/storage/blob/changefeed/ChangefeedNetworkTest.groovy b/sdk/storage/azure-storage-blob-changefeed/src/test/java/com/azure/storage/blob/changefeed/ChangefeedNetworkTest.groovy index 8445bd10aa58..fcdea2d5b68b 100644 --- a/sdk/storage/azure-storage-blob-changefeed/src/test/java/com/azure/storage/blob/changefeed/ChangefeedNetworkTest.groovy +++ b/sdk/storage/azure-storage-blob-changefeed/src/test/java/com/azure/storage/blob/changefeed/ChangefeedNetworkTest.groovy @@ -1,5 +1,6 @@ package com.azure.storage.blob.changefeed +import spock.lang.Ignore import reactor.test.StepVerifier import spock.lang.Requires import spock.lang.Unroll @@ -73,6 +74,7 @@ class ChangefeedNetworkTest extends APISpec { @Unroll @Requires( { playbackMode() }) + @Ignore("flaky in CI") def "get continuationToken"() { when: BlobChangefeedPagedIterable iterable = new BlobChangefeedClientBuilder(primaryBlobServiceClient) @@ -101,6 +103,7 @@ class ChangefeedNetworkTest extends APISpec { @Unroll @Requires( { playbackMode() }) + @Ignore("flaky in CI") def "resume continuationToken"() { when: BlobChangefeedPagedFlux flux = new BlobChangefeedClientBuilder(primaryBlobServiceAsyncClient)