@Override
    public Optional<FunctionAuthData> updateAuthData(Function.FunctionDetails funcDetails,
                                                     Optional<FunctionAuthData> existingFunctionAuthData,
                                                     AuthenticationDataSource authenticationDataSource)
            throws Exception {

        String secretId;
        secretId = existingFunctionAuthData.map(functionAuthData -> new String(functionAuthData.getData()))
                .orElseGet(() -> RandomStringUtils.random(5, true, true).toLowerCase());

        String token;
        try {
            token = getToken(authenticationDataSource);
        } catch (AuthenticationException e) {
            // No token is passed so delete the token. Might be trying to switch over to using anonymous user
            cleanUpAuthData(
                    funcDetails,
                    existingFunctionAuthData);
            return Optional.empty();
        }

        if (token != null) {
            upsertSecret(token, funcDetails, getSecretName(secretId));
            return Optional.of(FunctionAuthData.builder().data(secretId.getBytes()).build());
        }

        return existingFunctionAuthData;
    }
@Test
    public void testUpdateAuthData() throws Exception {
        CoreV1Api coreV1Api = mock(CoreV1Api.class);
        KubernetesSecretsTokenAuthProvider kubernetesSecretsTokenAuthProvider = new KubernetesSecretsTokenAuthProvider();
        kubernetesSecretsTokenAuthProvider.initialize(coreV1Api, null, (fd) -> "default");
        // test when existingFunctionAuthData is empty
        Optional<FunctionAuthData> existingFunctionAuthData = Optional.empty();
        Function.FunctionDetails funcDetails = Function.FunctionDetails.newBuilder().setTenant("test-tenant").setNamespace("test-ns").setName("test-func").build();
        Optional<FunctionAuthData> functionAuthData = kubernetesSecretsTokenAuthProvider.updateAuthData(funcDetails, existingFunctionAuthData, new AuthenticationDataSource() {
                    @Override
                    public boolean hasDataFromCommand() {
                        return true;
                    }

                    @Override
                    public String getCommandData() {
                        return "test-token";
                    }
                });


        Assert.assertTrue(functionAuthData.isPresent());
        Assert.assertTrue(StringUtils.isNotBlank(new String(functionAuthData.get().getData())));

        // test when existingFunctionAuthData is NOT empty
        existingFunctionAuthData = Optional.of(new FunctionAuthData("pf-secret-z7mxx".getBytes(), null));
        functionAuthData = kubernetesSecretsTokenAuthProvider.updateAuthData(funcDetails, existingFunctionAuthData, new AuthenticationDataSource() {
                    @Override
                    public boolean hasDataFromCommand() {
                        return true;
                    }

                    @Override
                    public String getCommandData() {
                        return "test-token";
                    }
                });


        Assert.assertTrue(functionAuthData.isPresent());
        Assert.assertEquals(new String(functionAuthData.get().getData()), "pf-secret-z7mxx");
    }