@@ -832,6 +832,69 @@ func TestEnsureResolved_HostMetadata_MissingAccountIdWithPlaceholder_Warns(t *te
832832 assert .Empty (t , cfg .DiscoveryURL )
833833}
834834
835+ func TestApplyHostMetadata_SetsTokenAudienceForAccountHost (t * testing.T ) {
836+ noopLoader := mockLoader (func (cfg * Config ) error { return nil })
837+ cfg := & Config {
838+ Host : testHMHost ,
839+ Experimental_IsUnifiedHost : true ,
840+ Loaders : []Loader {noopLoader },
841+ HTTPTransport : fixtures.SliceTransport {
842+ {
843+ Method : "GET" ,
844+ Resource : "/.well-known/databricks-config" ,
845+ Status : 200 ,
846+ Response : `{"oidc_endpoint": "` + testHMHost + `/oidc", "account_id": "` + testHMAccountID + `", "cloud": "AWS"}` ,
847+ },
848+ },
849+ }
850+ err := cfg .EnsureResolved ()
851+ require .NoError (t , err )
852+ // No workspace_id and has account_id → token audience should be set
853+ assert .Equal (t , testHMAccountID , cfg .TokenAudience )
854+ }
855+
856+ func TestApplyHostMetadata_NoTokenAudienceForWorkspaceHost (t * testing.T ) {
857+ noopLoader := mockLoader (func (cfg * Config ) error { return nil })
858+ cfg := & Config {
859+ Host : testHMHost ,
860+ Experimental_IsUnifiedHost : true ,
861+ Loaders : []Loader {noopLoader },
862+ HTTPTransport : fixtures.SliceTransport {
863+ {
864+ Method : "GET" ,
865+ Resource : "/.well-known/databricks-config" ,
866+ Status : 200 ,
867+ Response : `{"oidc_endpoint": "` + testHMHost + `/oidc", "account_id": "` + testHMAccountID + `", "workspace_id": "` + testHMWorkspaceID + `", "cloud": "AWS"}` ,
868+ },
869+ },
870+ }
871+ err := cfg .EnsureResolved ()
872+ require .NoError (t , err )
873+ // Has workspace_id → token audience should NOT be set
874+ assert .Empty (t , cfg .TokenAudience )
875+ }
876+
877+ func TestApplyHostMetadata_DoesNotOverrideExistingTokenAudience (t * testing.T ) {
878+ noopLoader := mockLoader (func (cfg * Config ) error { return nil })
879+ cfg := & Config {
880+ Host : testHMHost ,
881+ TokenAudience : "custom-audience" ,
882+ Experimental_IsUnifiedHost : true ,
883+ Loaders : []Loader {noopLoader },
884+ HTTPTransport : fixtures.SliceTransport {
885+ {
886+ Method : "GET" ,
887+ Resource : "/.well-known/databricks-config" ,
888+ Status : 200 ,
889+ Response : `{"oidc_endpoint": "` + testHMHost + `/oidc", "account_id": "` + testHMAccountID + `", "cloud": "AWS"}` ,
890+ },
891+ },
892+ }
893+ err := cfg .EnsureResolved ()
894+ require .NoError (t , err )
895+ assert .Equal (t , "custom-audience" , cfg .TokenAudience )
896+ }
897+
835898func TestConfig_ResolveHostMetadata_Clouds (t * testing.T ) {
836899 tests := []struct {
837900 name string
0 commit comments