Skip to content

Commit 3aa2f7f

Browse files
committed
add unit test for when call creds env var is disabled
1 parent 04f5958 commit 3aa2f7f

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

internal/xds/bootstrap/bootstrap_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,3 +1651,35 @@ func (s) TestBootstrap_SelectedChannelCredsAndCallCreds(t *testing.T) {
16511651
})
16521652
}
16531653
}
1654+
1655+
func (s) TestBootstrap_SelectedCallCreds_WhenNotCCNotEnabled(t *testing.T) {
1656+
testutils.SetEnvConfig(t, &envconfig.XDSBootstrapCallCredsEnabled, false)
1657+
config := `{
1658+
"server_uri": "xds-server:443",
1659+
"channel_creds": [{"type": "tls", "config": {}}],
1660+
"call_creds": [
1661+
{
1662+
"type": "jwt_token_file",
1663+
"config": {"jwt_token_file": "/token.jwt"}
1664+
}
1665+
]
1666+
}`
1667+
1668+
var sc ServerConfig
1669+
err := sc.UnmarshalJSON([]byte(config))
1670+
if err != nil {
1671+
t.Fatalf("Failed to unmarshal bootstrap config: %v", err)
1672+
}
1673+
1674+
// Verify call credentials processing.
1675+
callCredsConfig := sc.CallCredsConfigs()
1676+
dialOpts := sc.DialOptions()
1677+
if len(callCredsConfig) != 1 {
1678+
t.Errorf("Call creds configs count = %d, want %d", len(callCredsConfig), 1)
1679+
}
1680+
// Even though we have parsed the call creds configs, we are not using them
1681+
// because the env variable is not enabled.
1682+
if len(dialOpts) != 0 {
1683+
t.Errorf("Call creds count = %d, want %d", len(dialOpts), 0)
1684+
}
1685+
}

0 commit comments

Comments
 (0)