Repository: camel Updated Branches: refs/heads/master bde92230c -> d198385bb
CAMEL-11402 Logic error in authentication type ... ...determination This fixes the logic error and adds a test to confirm. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d198385b Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d198385b Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d198385b Branch: refs/heads/master Commit: d198385bb66bb44b3e56b79eab5b9b05b400e97b Parents: bde9223 Author: Zoran Regvart <zregv...@apache.org> Authored: Tue Jun 13 12:38:20 2017 +0200 Committer: Zoran Regvart <zregv...@apache.org> Committed: Tue Jun 13 12:38:20 2017 +0200 ---------------------------------------------------------------------- .../salesforce/SalesforceLoginConfig.java | 2 +- .../salesforce/SalesforceLoginConfigTest.java | 76 ++++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/d198385b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/SalesforceLoginConfig.java ---------------------------------------------------------------------- diff --git a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/SalesforceLoginConfig.java b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/SalesforceLoginConfig.java index 81ae0b1..742b214 100644 --- a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/SalesforceLoginConfig.java +++ b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/SalesforceLoginConfig.java @@ -154,7 +154,7 @@ public class SalesforceLoginConfig { return AuthenticationType.REFRESH_TOKEN; } - if (!hasPassword && hasRefreshToken && hasKeystore) { + if (!hasPassword && !hasRefreshToken && hasKeystore) { return AuthenticationType.JWT; } http://git-wip-us.apache.org/repos/asf/camel/blob/d198385b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/SalesforceLoginConfigTest.java ---------------------------------------------------------------------- diff --git a/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/SalesforceLoginConfigTest.java b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/SalesforceLoginConfigTest.java new file mode 100644 index 0000000..51e2055 --- /dev/null +++ b/components/camel-salesforce/camel-salesforce-component/src/test/java/org/apache/camel/component/salesforce/SalesforceLoginConfigTest.java @@ -0,0 +1,76 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.salesforce; + +import org.apache.camel.util.jsse.KeyStoreParameters; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class SalesforceLoginConfigTest { + + final SalesforceLoginConfig jwt; + + final SalesforceLoginConfig refreshToken; + + final SalesforceLoginConfig usernamePassword; + + public SalesforceLoginConfigTest() { + usernamePassword = new SalesforceLoginConfig(); + usernamePassword.setUserName("userName"); + usernamePassword.setPassword("password"); + usernamePassword.setClientId("clientId"); + usernamePassword.setClientSecret("clientSecret"); + + refreshToken = new SalesforceLoginConfig(); + refreshToken.setUserName("userName"); + refreshToken.setRefreshToken("refreshToken"); + refreshToken.setClientId("clientId"); + refreshToken.setClientSecret("clientSecret"); + + jwt = new SalesforceLoginConfig(); + jwt.setUserName("userName"); + final KeyStoreParameters keystore = new KeyStoreParameters(); + keystore.setResource("keystore.jks"); + jwt.setKeystore(keystore); + jwt.setClientId("clientId"); + } + + @Test + public void shouldDetermineProperAuthenticationType() { + assertEquals(AuthenticationType.USERNAME_PASSWORD, usernamePassword.getType()); + + assertEquals(AuthenticationType.REFRESH_TOKEN, refreshToken.getType()); + + assertEquals(AuthenticationType.JWT, jwt.getType()); + } + + @Test + public void shouldJwtParameters() { + jwt.validate(); + } + + @Test + public void shouldValidateRefreshTokenParameters() { + refreshToken.validate(); + } + + @Test + public void shouldValidateUsernamePasswordParameters() { + usernamePassword.validate(); + } +}