Skip to content

Commit

Permalink
Repeat smoke test on the host
Browse files Browse the repository at this point in the history
  • Loading branch information
divergentdave committed Nov 8, 2023
1 parent 165e062 commit ba8dae7
Show file tree
Hide file tree
Showing 15 changed files with 278 additions and 151 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion divviup/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {

android {
namespace = "org.divviup.android"
compileSdk = 33
compileSdk = 34

ndkVersion = "26.1.10909125"

Expand All @@ -30,7 +30,10 @@ android {

dependencies {
implementation("commons-io:commons-io:2.15.0")
testImplementation(project(":divviup:commontest"))
testImplementation("junit:junit:4.13.2")
testImplementation("com.squareup.okhttp3:mockwebserver:4.12.0")
androidTestImplementation(project(":divviup:commontest"))
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
androidTestImplementation("com.squareup.okhttp3:mockwebserver:4.12.0")
Expand Down
1 change: 1 addition & 0 deletions divviup/commontest/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
33 changes: 33 additions & 0 deletions divviup/commontest/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
plugins {
id("com.android.library")
}

android {
namespace = "org.divviup.commontest"
compileSdk = 34

defaultConfig {
minSdk = 21

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}

dependencies {
implementation("com.squareup.okhttp3:mockwebserver:4.12.0")
}
Empty file.
21 changes: 21 additions & 0 deletions divviup/commontest/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
4 changes: 4 additions & 0 deletions divviup/commontest/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.divviup.commontest;

import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;

import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okio.Buffer;

public class MockAggregator {
private static Buffer loadHpkeConfigList() throws IOException {
Buffer hpkeConfigListBuffer;
ClassLoader classLoader = Objects.requireNonNull(MockAggregator.class.getClassLoader());
try (InputStream is = classLoader.getResourceAsStream("hpke_config_list.bin")) {
hpkeConfigListBuffer = new Buffer();
hpkeConfigListBuffer.readFrom(is);
}
return hpkeConfigListBuffer;
}

public static MockWebServer setupMockServer() throws IOException {
Buffer hpkeConfigListBuffer = loadHpkeConfigList();
MockWebServer server = new MockWebServer();
server.enqueue(
new MockResponse()
.setHeader("Content-Type", "application/dap-hpke-config-list")
.setBody(hpkeConfigListBuffer)
);
server.enqueue(
new MockResponse()
.setHeader("Content-Type", "application/dap-hpke-config-list")
.setBody(hpkeConfigListBuffer)
);
server.enqueue(new MockResponse());
server.start();
return server;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package org.divviup.android;

import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.divviup.commontest.MockAggregator;
import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

import java.io.IOException;
import java.net.URI;

import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;

@RunWith(AndroidJUnit4.class)
public class InstrumentedSmokeTest {
private static final TaskId ZERO_TASK_ID = TaskId.parse("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");

@Test
public void smokeTestPrio3Count() throws IOException, InterruptedException {
try (MockWebServer server = MockAggregator.setupMockServer()) {
URI uri = server.url("/").uri();
Client<Boolean> client = Client.createPrio3Count(uri, uri, ZERO_TASK_ID, 300);
client.sendMeasurement(true);

basicUploadChecks(server);
}
}

@Test
public void smokeTestPrio3Sum() throws IOException, InterruptedException {
try (MockWebServer server = MockAggregator.setupMockServer()) {
URI uri = server.url("/").uri();
Client<Long> client = Client.createPrio3Sum(uri, uri, ZERO_TASK_ID, 300, 32);
client.sendMeasurement(1000000L);

basicUploadChecks(server);
}
}

@Test
public void smokeTestPrio3SumVec() throws IOException, InterruptedException {
try (MockWebServer server = MockAggregator.setupMockServer()) {
URI uri = server.url("/").uri();
Client<long[]> client = Client.createPrio3SumVec(uri, uri, ZERO_TASK_ID, 300, 10, 8, 12);
client.sendMeasurement(new long[] {252L, 7L, 80L, 194L, 190L, 217L, 141L, 85L, 222L, 243L});

basicUploadChecks(server);
}
}

@Test
public void smokeTestPrio3Histogram() throws IOException, InterruptedException {
try (MockWebServer server = MockAggregator.setupMockServer()) {
URI uri = server.url("/").uri();
Client<Long> client = Client.createPrio3Histogram(uri, uri, ZERO_TASK_ID, 300, 5, 2);
client.sendMeasurement(2L);

basicUploadChecks(server);
}
}

private static void basicUploadChecks(MockWebServer server) throws InterruptedException {
RecordedRequest r1 = server.takeRequest();
assertEquals(r1.getMethod(), "GET");
assertEquals(r1.getPath(), "/hpke_config?task_id=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");

RecordedRequest r2 = server.takeRequest();
assertEquals(r2.getMethod(), "GET");
assertEquals(r2.getPath(), "/hpke_config?task_id=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");

RecordedRequest r3 = server.takeRequest();
assertEquals(r3.getMethod(), "PUT");
assertEquals(r3.getPath(), "/tasks/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/reports");
assertEquals(r3.getHeader("Content-Type"), "application/dap-report");
assertTrue(r3.getBody().size() > 0);
}
}
18 changes: 18 additions & 0 deletions divviup/src/test/java/android/util/Base64.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package android.util;

public class Base64 {
public static final int NO_PADDING = 1, NO_WRAP = 2, URL_SAFE = 8;
private static final int DAP_BASE64_FLAGS = NO_PADDING | NO_WRAP | URL_SAFE;

public static String encodeToString(byte[] input, int flags) {
assert flags == DAP_BASE64_FLAGS;
java.util.Base64.Encoder encoder = java.util.Base64.getUrlEncoder().withoutPadding();
return encoder.encodeToString(input);
}

public static byte[] decode(String str, int flags) {
assert flags == DAP_BASE64_FLAGS;
java.util.Base64.Decoder decoder = java.util.Base64.getUrlDecoder();
return decoder.decode(str);
}
}
22 changes: 0 additions & 22 deletions divviup/src/test/java/org/divviup/android/ExampleUnitTest.java

This file was deleted.

Loading

0 comments on commit ba8dae7

Please sign in to comment.