Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Acquire live test jobId in tests.yml #18811

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng/common/TestResources/deploy-test-resources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ parameters:


steps:
- template: /eng/common/TestResources/setup-az-modules.yml
# - template: /eng/common/TestResources/setup-az-modules.yml

- pwsh: |
eng/common/TestResources/Import-AzModules.ps1
Expand Down
14 changes: 7 additions & 7 deletions eng/pipelines/templates/jobs/archetype-sdk-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ jobs:

- template: /eng/common/pipelines/templates/steps/bypass-local-dns.yml

- ${{ if ne(parameters.DisableAzureResourceCreation, 'true') }}:
- template: /eng/common/TestResources/deploy-test-resources.yml
parameters:
ServiceDirectory: '${{ parameters.ServiceDirectory }}'
SubscriptionConfiguration: $(SubscriptionConfiguration)
ArmTemplateParameters: $(ArmTemplateParameters)
Location: $(Location)
# - ${{ if ne(parameters.DisableAzureResourceCreation, 'true') }}:
# - template: /eng/common/TestResources/deploy-test-resources.yml
# parameters:
# ServiceDirectory: '${{ parameters.ServiceDirectory }}'
# SubscriptionConfiguration: $(SubscriptionConfiguration)
# ArmTemplateParameters: $(ArmTemplateParameters)
# Location: $(Location)

- ${{ parameters.PreRunSteps }}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.test.aad.selenium.ondemand;

import org.junit.After;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.ResponseEntity;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;
import java.util.HashMap;
import java.util.Map;

import static com.azure.spring.test.EnvironmentVariable.AAD_USER_NAME_ON_DEMAND;
import static com.azure.spring.test.EnvironmentVariable.AAD_USER_NAME_ON_DEMAND_FAKE;
import static com.azure.spring.test.EnvironmentVariable.AAD_USER_PASSWORD_1;

public class AADOnDemandIT {
private static final Logger LOGGER = LoggerFactory.getLogger(com.azure.test.aad.selenium.ondemand.AADOnDemandIT.class);
// private AADSeleniumITHelper aadSeleniumITHelper;

@Test
public void onDemandTest() {
Map<String, String> properties = new HashMap<>();
properties.put("azure.activedirectory.client-id", AAD_USER_NAME_ON_DEMAND);
properties.put("azure.activedirectory.client-secret", AAD_USER_PASSWORD_1);
String onDemandUser1 = AAD_USER_NAME_ON_DEMAND;
LOGGER.info(onDemandUser1);
String onDemandUser2 = AAD_USER_NAME_ON_DEMAND_FAKE;
LOGGER.info(onDemandUser2);

String username1 = onDemandUser1.split("@")[0];
LOGGER.info(username1);
String username2 = onDemandUser2.split("@")[0];
LOGGER.info(username2);

// aadSeleniumITHelper = new AADSeleniumITHelper(com.azure.test.aad.selenium.ondemand.AADOnDemandIT.class, properties,
// AAD_USER_NAME_2, AAD_USER_PASSWORD_2);
// aadSeleniumITHelper.logIn();
//
// String httpResponse = aadSeleniumITHelper.httpGet("api/home");
// Assert.assertTrue(httpResponse.contains("home"));
}

@After
public void destroy() {
// aadSeleniumITHelper.destroy();
}

@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true)
@SpringBootApplication
@RestController
public static class DumbApp {

@GetMapping(value = "/api/home")
public ResponseEntity<String> home(Principal principal) {
LOGGER.info(((OAuth2AuthenticationToken) principal).getAuthorities().toString());
return ResponseEntity.ok("home");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class EnvironmentVariable {
public static final String AAD_TENANT_ID_2 = System.getenv("AAD_TENANT_ID_2");
public static final String AAD_USER_NAME_1 = System.getenv("AAD_USER_NAME_1");
public static final String AAD_USER_NAME_2 = System.getenv("AAD_USER_NAME_2");
public static final String AAD_USER_NAME_ON_DEMAND = System.getenv("AAD_USER_NAME_ON_DEMAND");
public static final String AAD_USER_NAME_ON_DEMAND_FAKE = System.getenv("AAD_USER_NAME_ON_DEMAND_FAKE");
public static final String AAD_USER_PASSWORD_1 = System.getenv("AAD_USER_PASSWORD_1");
public static final String AAD_USER_PASSWORD_2 = System.getenv("AAD_USER_PASSWORD_2");
public static final String AZURE_KEYVAULT2_URI = System.getenv("AZURE_KEYVAULT2_URI");
Expand Down
101 changes: 64 additions & 37 deletions sdk/spring/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,48 @@ jobs:
goals: "verify"

Artifacts:
- name: azure-spring-boot-test-application
groupId: com.azure.spring
safeName: azurespringboottestapplication
# - name: azure-spring-boot-test-application
# groupId: com.azure.spring
# safeName: azurespringboottestapplication
- name: azure-spring-boot-test-core
groupId: com.azure.spring
safeName: azurespringboottestcore
- name: azure-spring-boot-test-cosmos
groupId: com.azure.spring
safeName: azurespringboottestcosmos
# - name: azure-spring-boot-test-cosmos
# groupId: com.azure.spring
# safeName: azurespringboottestcosmos
- name: azure-spring-boot-test-aad
groupId: com.azure.spring
safeName: azurespringboottestaad
- name: azure-spring-boot-test-aad-b2c
groupId: com.azure.spring
safeName: azurespringboottestaadb2c
- name: azure-spring-boot-test-aad-obo
groupId: com.azure.spring
safeName: azurespringboottestaadobo
- name: azure-spring-boot-test-aad-resource-server
groupId: com.azure.spring
safeName: azurespringboottestaadresourceserver
- name: azure-spring-boot-test-aad-resource-server-by-filter
groupId: com.azure.spring
safeName: azurespringboottestaadresourceserverbyfilter
- name: azure-spring-boot-test-keyvault
groupId: com.azure.spring
safeName: azurespringboottestkeyvault
- name: azure-spring-boot-test-keyvault-reactive
groupId: com.azure.spring
safeName: azurespringboottestkeyvaultreactive
- name: azure-spring-boot-test-parent
groupId: com.azure.spring
safeName: azurespringboottestparent
- name: azure-spring-boot-test-servicebus-jms
groupId: com.azure.spring
safeName: azurespringboottestservicebusjms
- name: azure-spring-cloud-test-eventhubs
groupId: com.azure.spring
safeName: azurespringcloudtesteventhubs
- name: azure-spring-boot-test-storage
groupId: com.azure.spring
safeName: azurespringbootteststorage
# - name: azure-spring-boot-test-aad-b2c
# groupId: com.azure.spring
# safeName: azurespringboottestaadb2c
# - name: azure-spring-boot-test-aad-obo
# groupId: com.azure.spring
# safeName: azurespringboottestaadobo
# - name: azure-spring-boot-test-aad-resource-server
# groupId: com.azure.spring
# safeName: azurespringboottestaadresourceserver
# - name: azure-spring-boot-test-aad-resource-server-by-filter
# groupId: com.azure.spring
# safeName: azurespringboottestaadresourceserverbyfilter
# - name: azure-spring-boot-test-keyvault
# groupId: com.azure.spring
# safeName: azurespringboottestkeyvault
# - name: azure-spring-boot-test-keyvault-reactive
# groupId: com.azure.spring
# safeName: azurespringboottestkeyvaultreactive
# - name: azure-spring-boot-test-parent
# groupId: com.azure.spring
# safeName: azurespringboottestparent
# - name: azure-spring-boot-test-servicebus-jms
# groupId: com.azure.spring
# safeName: azurespringboottestservicebusjms
# - name: azure-spring-cloud-test-eventhubs
# groupId: com.azure.spring
# safeName: azurespringcloudtesteventhubs
# - name: azure-spring-boot-test-storage
# groupId: com.azure.spring
# safeName: azurespringbootteststorage

EnvVars:
AZURE_TEST_MODE: LIVE
Expand All @@ -75,6 +75,20 @@ jobs:
AAD_B2C_USER_PASSWORD: $(java-spring-aad-b2c-user-password)
AAD_B2C_CLIENT_ID: $(java-spring-aad-b2c-client-id)
AAD_B2C_CLIENT_SECRET: $(java-spring-aad-b2c-client-secret)
AAD_USER_NAME_ON_DEMAND: "user$(System.JobId)@aadittest1.onmicrosoft.com"
AAD_USER_PASSWORD_ON_DEMAND: $(java-spring-aad-user-password-1)
AAD_SERVICE_PRICIPAL_CLIENT_ID: $(java-spring-aad-service-principal-client-id)
AAD_SERVICE_PRICIPAL_CLIENT_SECRET: $(java-spring-aad-service-principal-client-secret)

PreRunSteps:
- powershell: |
$env:AAD_USER_NAME_ON_DEMAND
az login --allow-no-subscriptions --tenant $(java-spring-aad-tenant-id-1) --service-principal -u $(java-spring-aad-service-principal-client-id) -p $(java-spring-aad-service-principal-client-secret)
az ad user create --user-principal-name "$env:AAD_USER_NAME_ON_DEMAND" --display-name "user$(System.JobId)" --password "$(java-spring-aad-user-password-1)" --force-change-password-next-login false
az logout
env:
AAD_USER_NAME_ON_DEMAND: "user$(System.JobId)@aadittest1.onmicrosoft.com"
displayName: 'Create On-demand test user'

PostRunSteps:
- script: |
Expand Down Expand Up @@ -122,4 +136,17 @@ jobs:
AAD_B2C_PROFILE_EDIT: "B2C_1_profileediting1"
AAD_B2C_USER_PASSWORD: $(java-spring-aad-b2c-user-password)
AAD_B2C_CLIENT_ID: $(java-spring-aad-b2c-client-id)
AAD_B2C_CLIENT_SECRET: $(java-spring-aad-b2c-client-secret)
AAD_B2C_CLIENT_SECRET: $(java-spring-aad-b2c-client-secret)
AAD_USER_NAME_ON_DEMAND: "user$(System.JobId)@aadittest1.onmicrosoft.com"
AAD_USER_PASSWORD_ON_DEMAND: $(java-spring-aad-user-password-1)
AAD_SERVICE_PRICIPAL_CLIENT_ID: $(java-spring-aad-service-principal-client-id)
AAD_SERVICE_PRICIPAL_CLIENT_SECRET: $(java-spring-aad-service-principal-client-secret)

- powershell: |
az login --allow-no-subscriptions --tenant $(java-spring-aad-tenant-id-1) --service-principal -u $(java-spring-aad-service-principal-client-id) -p $(java-spring-aad-service-principal-client-secret)
az ad user delete --id "$env:AAD_USER_NAME_ON_DEMAND"
az logout
env:
AAD_USER_NAME_ON_DEMAND: "user$(System.JobId)@aadittest1.onmicrosoft.com"
condition: always()
displayName: 'Delete On-demand test user'