Skip to content

Commit 0b47916

Browse files
committed
ci: testing
1 parent 99ac638 commit 0b47916

File tree

4 files changed

+44
-67
lines changed

4 files changed

+44
-67
lines changed

.github/workflows/build.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,41 @@ jobs:
145145
- name: benchmark
146146
run: pnpm vitest bench --run
147147

148+
e2e:
149+
needs:
150+
- build
151+
152+
strategy:
153+
fail-fast: false
154+
matrix:
155+
os:
156+
- ubuntu
157+
- macos
158+
- windows
159+
node:
160+
- 22
161+
- 24
162+
163+
runs-on: ${{ matrix.os }}-latest
164+
165+
name: e2e-${{ matrix.os }}-${{ matrix.node }}
166+
167+
steps:
168+
- uses: containerbase/internal-tools/setup@7c88f112d9360bccbbc11f830563c077e1cda40f # v3.14.13
169+
with:
170+
save-cache: true
171+
node-version: ${{ matrix.node }}
172+
173+
- name: fetch dist
174+
uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
175+
with:
176+
name: dist
177+
path: dist
178+
179+
- name: test
180+
run: pnpm test:teavm-wasm
181+
timeout-minutes: 1
182+
148183
release:
149184
needs:
150185
- lint

lib/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ plugins {
1515

1616
dependencies {
1717
implementation(libs.bouncycastle.bcpg)
18-
implementation(project(":tools:teavm-plugin"))
18+
// implementation(project(":tools:teavm-plugin"))
1919
teavm(teavm.libs.jsoApis)
2020
}
2121

Lines changed: 3 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
11
package com.github.renovatebot;
22

33
import java.io.ByteArrayInputStream;
4-
import java.io.ByteArrayOutputStream;
54
import java.io.IOException;
65
import java.nio.charset.StandardCharsets;
76

87
import org.bouncycastle.bcpg.ArmoredInputStream;
9-
import org.bouncycastle.openpgp.PGPCompressedData;
10-
import org.bouncycastle.openpgp.PGPEncryptedDataList;
118
import org.bouncycastle.openpgp.PGPException;
12-
import org.bouncycastle.openpgp.PGPLiteralData;
13-
import org.bouncycastle.openpgp.PGPObjectFactory;
14-
import org.bouncycastle.openpgp.PGPPrivateKey;
15-
import org.bouncycastle.openpgp.PGPPublicKeyEncryptedData;
16-
import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
17-
import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator;
18-
import org.bouncycastle.openpgp.operator.bc.BcPublicKeyDataDecryptorFactory;
19-
import org.bouncycastle.util.io.Streams;
209
import org.teavm.jso.JSExport;
2110

2211
public final class Main {
@@ -28,61 +17,11 @@ private Main() {
2817
@JSExport
2918
public static String decrypt(String key, String msg) throws IOException, PGPException {
3019
final var builder = ArmoredInputStream.builder().setIgnoreCRC(true);
31-
final var input = builder.build(new ByteArrayInputStream(msg.getBytes(StandardCharsets.UTF_8)));
32-
final var pgpFactory = new PGPObjectFactory(input, new BcKeyFingerprintCalculator());
33-
34-
var firstObject = pgpFactory.nextObject();
35-
if (!(firstObject instanceof PGPEncryptedDataList)) {
36-
firstObject = pgpFactory.nextObject();
37-
}
38-
39-
final var keyStream = builder.build(new ByteArrayInputStream(key.getBytes(StandardCharsets.UTF_8)));
40-
final var keyRing = new PGPSecretKeyRingCollection(
41-
keyStream,
42-
new BcKeyFingerprintCalculator());
43-
44-
PGPPrivateKey keyToUse = null;
45-
PGPPublicKeyEncryptedData encryptedData = null;
46-
final var encObjects = ((PGPEncryptedDataList) firstObject).getEncryptedDataObjects();
47-
48-
while (keyToUse == null && encObjects.hasNext()) {
49-
encryptedData = (PGPPublicKeyEncryptedData) encObjects.next();
50-
final var k = keyRing.getSecretKey(encryptedData.getKeyIdentifier().getKeyId());
51-
if (k != null) {
52-
keyToUse = k.extractPrivateKey(null);
53-
break;
54-
}
55-
}
56-
57-
if (keyToUse == null) {
58-
throw new PGPException("Cannot find secret key for message.");
59-
}
60-
61-
final var clearText = encryptedData.getDataStream(new BcPublicKeyDataDecryptorFactory(keyToUse));
62-
var message = new PGPObjectFactory(clearText, new BcKeyFingerprintCalculator()).nextObject();
63-
String result = null;
64-
65-
if (message instanceof PGPCompressedData data) {
66-
message = new PGPObjectFactory(data.getDataStream(), new BcKeyFingerprintCalculator()).nextObject();
67-
}
68-
69-
if (message instanceof PGPLiteralData literalData) {
70-
final var outputStream = new ByteArrayOutputStream();
71-
Streams.pipeAll(literalData.getInputStream(), outputStream);
72-
result = outputStream.toString(StandardCharsets.UTF_8);
73-
outputStream.close();
74-
} else {
75-
throw new PGPException("Message is not encoded correctly.");
76-
}
77-
78-
if (encryptedData.isIntegrityProtected() && !encryptedData.verify()) {
79-
throw new PGPException("Message failed integrity check!");
80-
}
20+
final var bytes = msg.getBytes(StandardCharsets.UTF_8);
21+
final var input = builder.build(new ByteArrayInputStream(bytes));
8122

8223
input.close();
83-
keyStream.close();
84-
clearText.close();
8524

86-
return result;
25+
return "test -> " + bytes.length;
8726
}
8827
}

test/teavm/wasm.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@ const expected = '{"o":"abc","r":"","v":"123"}';
88
const key = await readFixture(`private-pgp.pem`);
99

1010
const actual = await decrypt(key, fixMessage(msg), { runtime: 'wasm-java' });
11-
console.assert(actual === expected, 'Decryption failed');
12-
console.log('Decryption successful:', actual);
11+
if (actual !== expected) {
12+
console.log('Decryption failed:', actual);
13+
} else {
14+
console.log('Decryption successful:', actual);
15+
}

0 commit comments

Comments
 (0)