-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FFM-7214 - When FF SDK is not supplied API Key it retries causing tim…
…eout for Client APIs (#144) * FFM-7214 - When FF SDK is not supplied API Key it retries causing timeout for Client APIs What If authentication fails the SDK will no longer attempt to retry constantly. HarnessConnector will now throw MissingSdkKeyException if a blank/empty key is given. Why Platform team are reporting authentication getting stuck in a loop when a blank SDK key is given Testing New unit tests to ensure xVariations methods return default values after authentication has failed
- Loading branch information
1 parent
a09b86f
commit 3112fac
Showing
14 changed files
with
216 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/io/harness/cf/client/api/MissingSdkKeyException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.harness.cf.client.api; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
public class MissingSdkKeyException extends RuntimeException { | ||
|
||
private static final String MISSING_SDK_KEY = "SDK key cannot be empty!"; | ||
|
||
public MissingSdkKeyException() { | ||
super(MISSING_SDK_KEY); | ||
log.error(MISSING_SDK_KEY); | ||
} | ||
|
||
public MissingSdkKeyException(Exception ex) { | ||
super(MISSING_SDK_KEY, ex); | ||
log.error(MISSING_SDK_KEY, ex); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/test/java/io/harness/cf/client/api/dispatchers/Http403OnAuthDispatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.harness.cf.client.api.dispatchers; | ||
|
||
import com.google.common.util.concurrent.AtomicLongMap; | ||
import io.harness.cf.client.api.testutils.PollingAtomicLong; | ||
import java.util.Objects; | ||
import lombok.Getter; | ||
import lombok.SneakyThrows; | ||
import okhttp3.mockwebserver.*; | ||
import okhttp3.mockwebserver.MockResponse; | ||
import okhttp3.mockwebserver.RecordedRequest; | ||
|
||
public class Http403OnAuthDispatcher extends Dispatcher { | ||
|
||
private final PollingAtomicLong connectAttempts; | ||
|
||
public Http403OnAuthDispatcher(int minConnectToWaitFor) { | ||
connectAttempts = new PollingAtomicLong(minConnectToWaitFor); | ||
} | ||
|
||
@Getter final AtomicLongMap<String> urlMap = AtomicLongMap.create(); | ||
|
||
@Override | ||
@SneakyThrows | ||
public MockResponse dispatch(RecordedRequest recordedRequest) { | ||
System.out.println("DISPATCH GOT ------> " + recordedRequest.getPath()); | ||
connectAttempts.getAndIncrement(); | ||
urlMap.incrementAndGet(Objects.requireNonNull(recordedRequest.getPath())); | ||
return new MockResponse().setResponseCode(403); | ||
} | ||
|
||
public void waitForAllConnections(int waitTimeSeconds) throws InterruptedException { | ||
connectAttempts.waitForMinimumValueToBeReached( | ||
waitTimeSeconds, "any", "Did not get minimum number of connection attempts"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/test/java/io/harness/cf/client/connector/HarnessConnectorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.harness.cf.client.connector; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertInstanceOf; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.Mockito.mock; | ||
|
||
import io.harness.cf.client.api.MissingSdkKeyException; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class HarnessConnectorTest { | ||
|
||
@Test | ||
void shouldThrowExceptionWhenEmptyApiKeyIsGiven() { | ||
|
||
Exception thrown = | ||
assertThrows( | ||
MissingSdkKeyException.class, | ||
() -> new HarnessConnector("", mock(HarnessConfig.class)), | ||
"Exception was not thrown"); | ||
assertInstanceOf(MissingSdkKeyException.class, thrown); | ||
} | ||
|
||
@Test | ||
void shouldThrowExceptionWhenNullApiKeyIsGiven() { | ||
|
||
Exception thrown = | ||
assertThrows( | ||
NullPointerException.class, | ||
() -> new HarnessConnector(null, mock(HarnessConfig.class)), | ||
"Exception was not thrown"); | ||
assertInstanceOf(NullPointerException.class, thrown); | ||
} | ||
} |