diff --git a/eng/common/TestResources/deploy-test-resources.yml b/eng/common/TestResources/deploy-test-resources.yml index a9d693b99420..f111fc2ccb60 100644 --- a/eng/common/TestResources/deploy-test-resources.yml +++ b/eng/common/TestResources/deploy-test-resources.yml @@ -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 diff --git a/eng/pipelines/templates/jobs/archetype-sdk-tests.yml b/eng/pipelines/templates/jobs/archetype-sdk-tests.yml index 12ae6f682a15..12074f85e232 100644 --- a/eng/pipelines/templates/jobs/archetype-sdk-tests.yml +++ b/eng/pipelines/templates/jobs/archetype-sdk-tests.yml @@ -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 }} diff --git a/sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/selenium/ondemand/AADOnDemandIT.java b/sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/selenium/ondemand/AADOnDemandIT.java new file mode 100644 index 000000000000..053894cbf888 --- /dev/null +++ b/sdk/spring/azure-spring-boot-test-aad/src/test/java/com/azure/test/aad/selenium/ondemand/AADOnDemandIT.java @@ -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 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 home(Principal principal) { + LOGGER.info(((OAuth2AuthenticationToken) principal).getAuthorities().toString()); + return ResponseEntity.ok("home"); + } + } +} \ No newline at end of file diff --git a/sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/spring/test/EnvironmentVariable.java b/sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/spring/test/EnvironmentVariable.java index 4ddbe354e6b2..09ffc1a87100 100644 --- a/sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/spring/test/EnvironmentVariable.java +++ b/sdk/spring/azure-spring-boot-test-core/src/main/java/com/azure/spring/test/EnvironmentVariable.java @@ -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"); diff --git a/sdk/spring/tests.yml b/sdk/spring/tests.yml index 1e33f99ead27..01e05c973fa1 100644 --- a/sdk/spring/tests.yml +++ b/sdk/spring/tests.yml @@ -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 @@ -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: | @@ -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) \ No newline at end of file + 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'