2019-05-31 18:37:43 -04:00
|
|
|
package client
|
2016-04-21 19:50:03 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2018-01-22 20:21:10 -05:00
|
|
|
|
|
|
|
"github.com/Azure/go-autorest/autorest/azure"
|
2016-04-21 19:50:03 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// Behavior is the most important thing to assert for ServicePrincipalToken, but
|
|
|
|
// that cannot be done in a unit test because it involves network access. Instead,
|
2018-03-13 04:05:14 -04:00
|
|
|
// I assert the expected inertness of this class.
|
2019-01-10 18:21:16 -05:00
|
|
|
func TestNewSecretOAuthTokenProvider(t *testing.T) {
|
|
|
|
testSubject := NewSecretOAuthTokenProvider(azure.PublicCloud, "clientID", "clientString", "tenantID")
|
2016-04-21 19:50:03 -04:00
|
|
|
spn, err := testSubject.getServicePrincipalToken()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf(err.Error())
|
|
|
|
}
|
|
|
|
|
2018-04-11 11:25:33 -04:00
|
|
|
if spn.Token().AccessToken != "" {
|
|
|
|
t.Errorf("spn.Token().AccessToken: expected=\"\", actual=%s", spn.Token().AccessToken)
|
2016-04-21 19:50:03 -04:00
|
|
|
}
|
2018-04-11 11:25:33 -04:00
|
|
|
if spn.Token().RefreshToken != "" {
|
|
|
|
t.Errorf("spn.Token().RefreshToken: expected=\"\", actual=%s", spn.Token().RefreshToken)
|
2016-04-21 19:50:03 -04:00
|
|
|
}
|
2019-05-30 17:25:43 -04:00
|
|
|
if spn.Token().ExpiresIn != "0" {
|
|
|
|
t.Errorf("spn.Token().ExpiresIn: expected=\"0\", actual=%s", spn.Token().ExpiresIn)
|
2016-04-21 19:50:03 -04:00
|
|
|
}
|
2019-05-30 17:25:43 -04:00
|
|
|
if spn.Token().ExpiresOn != "0" {
|
|
|
|
t.Errorf("spn.Token().ExpiresOn: expected=\"0\", actual=%s", spn.Token().ExpiresOn)
|
2016-04-21 19:50:03 -04:00
|
|
|
}
|
2019-05-30 17:25:43 -04:00
|
|
|
if spn.Token().NotBefore != "0" {
|
|
|
|
t.Errorf("spn.Token().NotBefore: expected=\"0\", actual=%s", spn.Token().NotBefore)
|
2016-04-21 19:50:03 -04:00
|
|
|
}
|
2018-04-11 11:25:33 -04:00
|
|
|
if spn.Token().Resource != "" {
|
|
|
|
t.Errorf("spn.Token().Resource: expected=\"\", actual=%s", spn.Token().Resource)
|
2016-04-21 19:50:03 -04:00
|
|
|
}
|
2018-04-11 11:25:33 -04:00
|
|
|
if spn.Token().Type != "" {
|
|
|
|
t.Errorf("spn.Token().Type: expected=\"\", actual=%s", spn.Token().Type)
|
2016-04-21 19:50:03 -04:00
|
|
|
}
|
|
|
|
}
|