@@ -21,25 +21,33 @@ const ExampleAPIModel = `{
2121 "windowsProfile": { "adminUsername": "azureuser", "adminPassword": "replacepassword1234$" },
2222 "linuxProfile": { "adminUsername": "azureuser", "ssh": { "publicKeys": [ { "keyData": "" } ] }
2323 },
24- "servicePrincipalProfile": { "servicePrincipalClientID": "", "servicePrincipalClientSecret": "" }
24+ "servicePrincipalProfile": { "servicePrincipalClientID": "%s ", "servicePrincipalClientSecret": "%s " }
2525 }
2626}
2727`
2828
29- func getExampleAPIModel (useManagedIdentity bool ) string {
30- return fmt .Sprintf (ExampleAPIModel , strconv .FormatBool (useManagedIdentity ))
29+ func getExampleAPIModel (useManagedIdentity bool , clientID , clientSecret string ) string {
30+ return fmt .Sprintf (
31+ ExampleAPIModel ,
32+ strconv .FormatBool (useManagedIdentity ),
33+ clientID ,
34+ clientSecret )
3135}
3236
3337func TestAutofillApimodelWithoutManagedIdentityCreatesCreds (t * testing.T ) {
34- testMSIPopulatedInternal (t , false )
38+ testAutodeployCredentialHandling (t , false , "" , "" )
3539}
3640
3741func TestAutofillApimodelWithManagedIdentitySkipsCreds (t * testing.T ) {
38- testMSIPopulatedInternal (t , true )
42+ testAutodeployCredentialHandling (t , true , "" , "" )
3943}
4044
41- func testMSIPopulatedInternal (t * testing.T , useManagedIdentity bool ) {
42- apimodel := getExampleAPIModel (useManagedIdentity )
45+ func TestAutofillApimodelAllowsPrespecifiedCreds (t * testing.T ) {
46+ testAutodeployCredentialHandling (t , false , "clientID" , "clientSecret" )
47+ }
48+
49+ func testAutodeployCredentialHandling (t * testing.T , useManagedIdentity bool , clientID , clientSecret string ) {
50+ apimodel := getExampleAPIModel (useManagedIdentity , clientID , clientSecret )
4351 cs , ver , err := api .DeserializeContainerService ([]byte (apimodel ), false )
4452 if err != nil {
4553 t .Fatalf ("unexpected error deserializing the example apimodel: %s" , err )
@@ -51,7 +59,7 @@ func testMSIPopulatedInternal(t *testing.T, useManagedIdentity bool) {
5159 deployCmd := & deployCmd {
5260 apimodelPath : "./this/is/unused.json" ,
5361 dnsPrefix : "dnsPrefix1" ,
54- outputDirectory : "dummy/path/ " ,
62+ outputDirectory : "_test_output " ,
5563 location : "westus" ,
5664
5765 containerService : cs ,
@@ -62,6 +70,9 @@ func testMSIPopulatedInternal(t *testing.T, useManagedIdentity bool) {
6270
6371 autofillApimodel (deployCmd )
6472
73+ // cleanup, since auto-populations creates dirs and saves the SSH private key that it might create
74+ defer os .RemoveAll (deployCmd .outputDirectory )
75+
6576 cs , ver , err = revalidateApimodel (cs , ver )
6677 if err != nil {
6778 log .Fatalf ("unexpected error validating apimodel after populating defaults: %s" , err )
@@ -78,7 +89,4 @@ func testMSIPopulatedInternal(t *testing.T, useManagedIdentity bool) {
7889 log .Fatalf ("Credentials were missing even though MSI was not active." )
7990 }
8091 }
81-
82- // cleanup, since auto-populations creates dirs and saves the SSH private key that it might create
83- os .RemoveAll (deployCmd .outputDirectory )
8492}
0 commit comments