Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 4.2.0 #663

Merged
merged 12 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
4.2.0 (Jun 28, 2024)
- Added certificate pinning functionality. This feature allows you to pin a certificate to the SDK, ensuring that the SDK only communicates with servers that present this certificate. Read more in our documentation.

4.1.1 (Jun 6, 2024)
- Fixed concurrency issue when building URLs.

Expand Down
9 changes: 6 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {

dependencies {
classpath 'com.android.tools.build:gradle:7.4.2'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21'
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0'
}
}

Expand All @@ -17,7 +17,7 @@ apply plugin: 'kotlin-android'
apply from: 'spec.gradle'

ext {
splitVersion = '4.1.1'
splitVersion = '4.2.0'
}

android {
Expand Down Expand Up @@ -111,7 +111,7 @@ dependencies {
def hamcrestVersion = '1.3'
def apacheCommonsVersion = '3.12.0'
def kotlinVer = '1.5.31'
def mockWebServerVersion = '3.12.13'
def mockWebServerVersion = '4.12.0'

def testRulesVersion = '1.4.0'
def jUnitExtVersion = '1.1.3'
Expand Down Expand Up @@ -142,6 +142,7 @@ dependencies {
testImplementation "org.hamcrest:hamcrest-all:$hamcrestVersion"
testImplementation "org.apache.commons:commons-lang3:$apacheCommonsVersion"
testImplementation "com.squareup.okhttp3:mockwebserver:$mockWebServerVersion"
testImplementation "com.squareup.okhttp3:okhttp-tls:$mockWebServerVersion"
testImplementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVer"
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlinVer"
testImplementation "com.google.guava:guava:$guavaVersion"
Expand All @@ -152,11 +153,13 @@ dependencies {
androidTestUtil "androidx.test:orchestrator:$orchestratorVersion"

androidTestImplementation "com.squareup.okhttp3:mockwebserver:$mockWebServerVersion"
androidTestImplementation "com.squareup.okhttp3:okhttp-tls:$mockWebServerVersion"
androidTestImplementation "androidx.room:room-testing:$roomVersion"
androidTestImplementation "androidx.work:work-testing:$workVersion"
androidTestImplementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVer"
androidTestImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlinVer"
androidTestImplementation "com.google.guava:guava:$guavaVersion"
androidTestImplementation "org.mockito:mockito-android:$mockitoVersion"
}

def splitPOM = {
Expand Down
8 changes: 8 additions & 0 deletions src/androidTest/java/helper/IntegrationHelper.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package helper;

import android.content.Context;
import android.util.Base64;

import androidx.annotation.Nullable;
import androidx.core.util.Pair;
Expand All @@ -15,6 +16,8 @@
import java.lang.reflect.Type;
import java.net.URI;
import java.net.URLDecoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -336,6 +339,11 @@ public HttpStreamResponseMock getStreamResponse(URI uri) {
};
}

public static String sha256(byte[] encoded) throws NoSuchAlgorithmException {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
return Base64.encodeToString(digest.digest(encoded), Base64.NO_WRAP);
}

/**
* A simple interface to allow us to define the response for a given path
*/
Expand Down
18 changes: 16 additions & 2 deletions src/androidTest/java/helper/TestableSplitConfigBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.split.android.client.SplitClientConfig;
import io.split.android.client.SyncConfig;
import io.split.android.client.impressions.ImpressionListener;
import io.split.android.client.network.CertificatePinningConfiguration;
import io.split.android.client.network.DevelopmentSslConfig;
import io.split.android.client.network.SplitAuthenticator;
import io.split.android.client.service.ServiceConstants;
Expand Down Expand Up @@ -60,8 +61,9 @@ public class TestableSplitConfigBuilder {
private long mDefaultSSEConnectionDelayInSecs = ServiceConstants.DEFAULT_SSE_CONNECTION_DELAY_SECS;
private long mSSEDisconnectionDelayInSecs = 60L;
private long mObserverCacheExpirationPeriod = ServiceConstants.DEFAULT_OBSERVER_CACHE_EXPIRATION_PERIOD_MS;

private String mPrefix = "";
private CertificatePinningConfiguration mCertificatePinningConfiguration;
private long mImpressionsDedupeTimeInterval = ServiceConstants.DEFAULT_IMPRESSIONS_DEDUPE_TIME_INTERVAL;

public TestableSplitConfigBuilder() {
mServiceEndpoints = ServiceEndpoints.builder().build();
Expand Down Expand Up @@ -262,6 +264,16 @@ public TestableSplitConfigBuilder observerCacheExpirationPeriod(long observerCac
return this;
}

public TestableSplitConfigBuilder certificatePinningConfiguration(CertificatePinningConfiguration certificatePinningConfiguration) {
this.mCertificatePinningConfiguration = certificatePinningConfiguration;
return this;
}

public TestableSplitConfigBuilder impressionsDedupeTimeInterval(long impressionsDedupeTimeInterval) {
this.mImpressionsDedupeTimeInterval = impressionsDedupeTimeInterval;
return this;
}

public SplitClientConfig build() {
Constructor constructor = SplitClientConfig.class.getDeclaredConstructors()[0];
constructor.setAccessible(true);
Expand Down Expand Up @@ -315,7 +327,9 @@ public SplitClientConfig build() {
mDefaultSSEConnectionDelayInSecs,
mSSEDisconnectionDelayInSecs,
mPrefix,
mObserverCacheExpirationPeriod);
mObserverCacheExpirationPeriod,
mCertificatePinningConfiguration,
mImpressionsDedupeTimeInterval);

Logger.instance().setLevel(mLogLevel);
return config;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.split.android.client.service.impressions;

import static org.junit.Assert.assertTrue;

import org.junit.Test;

import java.util.concurrent.TimeUnit;

public class ImpressionUtilsTest {

@Test
public void truncateTimeframe() {
long timestampInMs = System.currentTimeMillis();
assertCorrectTruncation(timestampInMs, TimeUnit.SECONDS.toMillis(3));
assertCorrectTruncation(timestampInMs, TimeUnit.MINUTES.toMillis(36));
assertCorrectTruncation(timestampInMs, TimeUnit.MINUTES.toMillis(80));
assertCorrectTruncation(timestampInMs, TimeUnit.HOURS.toMillis(1));
assertCorrectTruncation(timestampInMs, TimeUnit.DAYS.toMillis(2));
}

private static void assertCorrectTruncation(long timestampInMs, long timeIntervalMs) {
long truncateOneSecond = ImpressionUtils.truncateTimeframe(timestampInMs, timeIntervalMs);

long timeDifference = timestampInMs - truncateOneSecond;
assertTrue(timeDifference < timeIntervalMs);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ public void expiredObserverCacheValuesExistingInDatabaseAreRemovedOnStartup() th
SplitClient client = initSplitFactory(new TestableSplitConfigBuilder()
.impressionsMode(ImpressionsMode.DEBUG)
.enableDebug()
.impressionsDedupeTimeInterval(1)
.observerCacheExpirationPeriod(100), mHttpClient).client();

client.getTreatment("FACUNDO_TEST");
Expand Down Expand Up @@ -254,6 +255,37 @@ public void close() {
assertEquals(threadId, listenerThreadId.get());
}

@Test
public void impressionsAreDedupedDuringDedupeInterval() throws InterruptedException {
SplitClient client = initSplitFactory(new TestableSplitConfigBuilder()
.impressionsMode(ImpressionsMode.OPTIMIZED)
.impressionsDedupeTimeInterval(500)
.enableDebug()
.impressionListener(new ImpressionListener() {
@Override
public void log(Impression impression) {
mImpressionsListenerCount.incrementAndGet();
}

@Override
public void close() {

}
}), mHttpClient).client();

for (int i = 0; i < 5; i++) {
client.getTreatment("FACUNDO_TEST");
}
Thread.sleep(600); // delay for dedupe interval
for (int i = 0; i < 5; i++) {
client.getTreatment("FACUNDO_TEST");
}
Thread.sleep(200); // delay for persistence

assertEquals(2, mDatabase.impressionDao().getAll().size()); // impressions after the interval passes are not deduped
assertEquals(10, mImpressionsListenerCount.get()); // all impressions are received by listener
}

private HttpResponseMockDispatcher getDispatcher() {
Map<String, IntegrationHelper.ResponseClosure> responses = new HashMap<>();
responses.put("splitChanges", (uri, httpMethod, body) -> {
Expand Down
Loading
Loading