Skip to content

Commit 5b82c58

Browse files
authored
Merge pull request #511 from AzureAD/4gust/keyvault-labauth
Updating pipeline to connect to ADO for integration tests
2 parents 7fe113d + 79e0339 commit 5b82c58

File tree

3 files changed

+70
-72
lines changed

3 files changed

+70
-72
lines changed

ado/build_test.yaml

Lines changed: 46 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,48 @@
1-
trigger:
2-
- main
1+
trigger:
2+
- main
33

44
pool:
5-
vmImage: 'ubuntu-latest'
6-
7-
steps:
8-
- task: GoTool@0
9-
inputs:
10-
version: '1.22.3'
11-
- task: Go@0
12-
inputs:
13-
command: 'get'
14-
arguments: '-d -v -t -d ./...'
15-
workingDirectory: '$(System.DefaultWorkingDirectory)'
16-
displayName: "Install dependencies"
17-
- task: Go@0
18-
inputs:
19-
command: 'build'
20-
arguments: './apps/...'
21-
workingDirectory: '$(System.DefaultWorkingDirectory)'
22-
displayName: "Build"
23-
# - task: Go@0
24-
# inputs:
25-
# command: 'test'
26-
# arguments: '-race -short ./apps/cache/... ./apps/confidential/... ./apps/public/... ./apps/internal/...'
27-
# workingDirectory: '$(System.DefaultWorkingDirectory)'
28-
# displayName: "Run Unit Tests"
29-
30-
- task: AzureKeyVault@2
31-
displayName: 'Connect to Key Vault'
32-
inputs:
33-
azureSubscription: 'AuthSdkResourceManager' # string. Workload identity service connection to use managed identity authentication
34-
KeyVaultName: 'msidlabs' # string. Required. The name of the Key Vault containing the secrets.
35-
#setting secrets filter to fetch only MSIDLABCertificate cert from the vault
36-
SecretsFilter: 'LabAuth' # string. Required. Specifies the secret to download. Use '*' for all secrets.
37-
#RunAsPreJob: false # boolean. Make secrets available to whole job. Default: false.
38-
39-
# - powershell: |
40-
# $kvSecretBytes = [System.Convert]::FromBase64String('$(LabAuth)')
41-
# $certCollection = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2Collection
42-
# $certCollection.Import($kvSecretBytes, $null, [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable)
43-
44-
# $protectedCertificateBytes = $certCollection.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Pkcs12)
45-
# $pfxPath = '$(Build.SourcesDirectory)' + "\TestCert.pfx"
46-
# [System.IO.File]::WriteAllBytes($pfxPath, $protectedCertificateBytes)
47-
48-
# Import-PfxCertificate -FilePath $pfxPath -CertStoreLocation Cert:\LocalMachine\My
49-
50-
# displayName: 'Install Keyvault Secrets'
51-
52-
- script: |
53-
echo $(LabAuth) | base64 -d > cert.pfx
54-
sudo apt-get install -y libnss3-tools openssl
55-
mkdir -p ~/.pki/nssdb
56-
certutil -N -d sql:$HOME/.pki/nssdb --empty-password
57-
openssl pkcs12 -in cert.pfx -out cert.pem -nodes
58-
certutil -A -d sql:$HOME/.pki/nssdb -n "labCert" -t "P,," -i cert.pem
59-
displayName: 'Install Keyvault Secrets'
60-
61-
- task: Go@0
62-
inputs:
63-
command: 'test'
64-
arguments: '-race ./apps/tests/integration/...'
65-
workingDirectory: '$(System.DefaultWorkingDirectory)'
66-
displayName: "Run Integration Tests"
67-
68-
5+
vmImage: "ubuntu-latest"
6+
7+
steps:
8+
- task: GoTool@0
9+
inputs:
10+
version: "1.22.3"
11+
- task: Go@0
12+
inputs:
13+
command: "get"
14+
arguments: "-d -v -t -d ./..."
15+
workingDirectory: "$(System.DefaultWorkingDirectory)"
16+
displayName: "Install dependencies"
17+
- task: Go@0
18+
inputs:
19+
command: "build"
20+
arguments: "./apps/..."
21+
workingDirectory: "$(System.DefaultWorkingDirectory)"
22+
displayName: "Build"
23+
- task: Go@0
24+
inputs:
25+
command: "test"
26+
arguments: "-race -short ./apps/cache/... ./apps/confidential/... ./apps/public/... ./apps/internal/..."
27+
workingDirectory: "$(System.DefaultWorkingDirectory)"
28+
displayName: "Run Unit Tests"
29+
- task: AzureKeyVault@2
30+
displayName: "Connect to Key Vault"
31+
inputs:
32+
azureSubscription: "AuthSdkResourceManager"
33+
KeyVaultName: "msidlabs"
34+
SecretsFilter: "LabAuth"
35+
- task: Bash@3
36+
displayName: Installing certificate
37+
inputs:
38+
targetType: "inline"
39+
script: |
40+
echo $(LabAuth) | base64 -d > $(Build.SourcesDirectory)/cert.pfx
41+
openssl pkcs12 -in $(Build.SourcesDirectory)/cert.pfx -out $(Build.SourcesDirectory)/cert.pem -nodes -passin pass:''
42+
43+
- task: Go@0
44+
inputs:
45+
command: "test"
46+
arguments: "-race ./apps/tests/integration/..."
47+
workingDirectory: "$(System.DefaultWorkingDirectory)"
48+
displayName: "Run Integration Tests"

apps/tests/integration/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Go Integration Test
2+
3+
This guide explains how to:
4+
5+
1. Download a certificate from [link](https://ms.portal.azure.com/#@microsoft.onmicrosoft.com/asset/Microsoft_Azure_KeyVault/Certificate/https://msidlabs.vault.azure.net/certificates/LabAuth).
6+
2. Download the `.pex/.pem` format
7+
3. Convert the `.cert` file to `.pem` file.
8+
4. Execute Go integration tests.
9+
10+
## Prerequisites
11+
12+
- Run `openssl pkcs12 -in <path to the cert>/cert.pfx -out <Go source folder>/cert.pem -nodes -passin pass:''`
13+
- It should be in the root folder of the `microsoft-authentication-library-for-go`
14+
15+
## Steps
16+
17+
### 1. Running the tests
18+
19+
```bash
20+
go test -race ./apps/tests/integration/
21+
```

apps/tests/integration/integration_test.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const (
3636

3737
// Default values
3838
defaultClientId = "f62c5ae3-bf3a-4af5-afa8-a68b800396e9"
39-
pemFile = "Insert path to pem file here"
39+
pemFile = "../../../cert.pem"
4040
)
4141

4242
var httpClient = http.Client{}
@@ -242,8 +242,7 @@ func TestUsernamePassword(t *testing.T) {
242242

243243
// TODO: update this at a later date, see issue https://github.com/AzureAD/microsoft-authentication-library-for-go/issues/513
244244
func TestConfidentialClientWithSecret(t *testing.T) {
245-
t.Skip("skipping integration test until it is fixed")
246-
245+
t.Skip("Skipping test until fix")
247246
if testing.Short() {
248247
t.Skip("skipping integration test")
249248
}
@@ -273,13 +272,11 @@ func TestConfidentialClientWithSecret(t *testing.T) {
273272
if silentResult.AccessToken == "" {
274273
t.Fatal("TestConfidentialClientwithSecret: on AcquireTokenSilent(): got AccessToken == '', want AccessToken != ''")
275274
}
276-
277275
}
278276

279277
// TODO: update this at a later date, see issue https://github.com/AzureAD/microsoft-authentication-library-for-go/issues/513
280278
func TestOnBehalfOf(t *testing.T) {
281-
t.Skip("skipping integration test until it is fixed")
282-
279+
t.Skip("Skipping test until fix")
283280
if testing.Short() {
284281
t.Skip("skipping integration test")
285282
}

0 commit comments

Comments
 (0)