diff --git a/pulsar-function-go/pf/instanceConf_test.go b/pulsar-function-go/pf/instanceConf_test.go index cc5f46e2fe12b..ca0ab57e780d7 100644 --- a/pulsar-function-go/pf/instanceConf_test.go +++ b/pulsar-function-go/pf/instanceConf_test.go @@ -20,6 +20,7 @@ package pf import ( + "encoding/json" "fmt" "testing" @@ -320,3 +321,26 @@ func TestInstanceConf_WithEmptyOrInvalidDetails(t *testing.T) { }) } } + +func TestInstanceConf_WithOAuth2Parameters(t *testing.T) { + cfg := &cfg.Conf{ + AutoACK: true, + ClientAuthenticationPlugin: "org.apache.pulsar.client.impl.auth.AuthenticationOAuth2", + ClientAuthenticationParameters: `{"issuerUrl":"https://test.com","audience":"test-audience", +"scope":"test-scope","privateKey":"/mnt/secrets/auth.json","type":"client_credentials","clientId":"test-client-id"}`, + } + + instanceConf := newInstanceConfWithConf(cfg) + assert.Equal(t, cfg.ClientAuthenticationPlugin, instanceConf.authPlugin) + var authMap map[string]string + err := json.Unmarshal([]byte(instanceConf.authParams), &authMap) + assert.Equal(t, err, nil) + assert.Equal(t, authMap, map[string]string{ + "issuerUrl": "https://test.com", + "audience": "test-audience", + "scope": "test-scope", + "privateKey": "/mnt/secrets/auth.json", + "type": "client_credentials", + "clientId": "test-client-id", + }) +}