Skip to content

Commit 941ac2f

Browse files
committed
Allow new-style DSNs without the secret key.
1 parent f3d6678 commit 941ac2f

4 files changed

Lines changed: 17 additions & 12 deletions

File tree

CHANGES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Version 1.7.4
22
-------------
33

4-
-
4+
- Allow new-style DSNs without the secret key.
55

66
Version 1.7.3
77
-------------

sentry/src/main/java/io/sentry/connection/AbstractConnection.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import io.sentry.environment.SentryEnvironment;
44
import io.sentry.event.Event;
5+
import io.sentry.util.Util;
56
import org.slf4j.Logger;
67
import org.slf4j.LoggerFactory;
78

@@ -47,8 +48,8 @@ protected AbstractConnection(String publicKey, String secretKey) {
4748
this.eventSendCallbacks = new HashSet<>();
4849
this.authHeader = "Sentry sentry_version=" + SENTRY_PROTOCOL_VERSION + ","
4950
+ "sentry_client=" + SentryEnvironment.getSentryName() + ","
50-
+ "sentry_key=" + publicKey + ","
51-
+ "sentry_secret=" + secretKey;
51+
+ "sentry_key=" + publicKey
52+
+ (!Util.isNullOrEmpty(secretKey) ? (",sentry_secret=" + secretKey) : "");
5253
}
5354

5455
/**

sentry/src/main/java/io/sentry/dsn/Dsn.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ private void makeOptionsImmutable() {
185185
/**
186186
* Validates internally the DSN, and check for mandatory elements.
187187
* <p>
188-
* Mandatory elements are the {@link #host}, {@link #publicKey}, {@link #secretKey} and {@link #projectId}.
188+
* Mandatory elements are the {@link #host}, {@link #publicKey} and {@link #projectId}.
189189
*/
190190
private void validate() {
191191
List<String> missingElements = new LinkedList<>();
@@ -200,9 +200,6 @@ private void validate() {
200200
if (publicKey == null) {
201201
missingElements.add("public key");
202202
}
203-
if (secretKey == null) {
204-
missingElements.add("secret key");
205-
}
206203
if (projectId == null || projectId.isEmpty()) {
207204
missingElements.add("project ID");
208205
}

sentry/src/test/java/io/sentry/dsn/DsnTest.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ public void testSimpleDsnFromValidURI() throws Exception {
5757
assertThat(dsn.getProjectId(), is("9"));
5858
}
5959

60+
@Test
61+
public void testSimpleDsnNoSecretValid() throws Exception {
62+
Dsn dsn = new Dsn("http://publicKey@host/9");
63+
64+
assertThat(dsn.getProtocol(), is("http"));
65+
assertThat(dsn.getPublicKey(), is("publicKey"));
66+
assertThat(dsn.getSecretKey(), isEmptyOrNullString());
67+
assertThat(dsn.getHost(), is("host"));
68+
assertThat(dsn.getPath(), is("/"));
69+
assertThat(dsn.getProjectId(), is("9"));
70+
}
71+
6072
@Test
6173
public void testDsnLookupWithNothingSet() throws Exception {
6274
assertThat(Dsn.dsnLookup(), is(Dsn.DEFAULT_DSN));
@@ -127,11 +139,6 @@ public void testDsnLookupWithEmptyEnvironmentVariable(@Mocked("getenv") final Sy
127139
assertThat(Dsn.dsnLookup(), is(Dsn.DEFAULT_DSN));
128140
}
129141

130-
@Test(expectedExceptions = InvalidDsnException.class)
131-
public void testMissingSecretKeyInvalid() throws Exception {
132-
new Dsn("http://publicKey:@host/9");
133-
}
134-
135142
@Test(expectedExceptions = InvalidDsnException.class)
136143
public void testMissingHostInvalid() throws Exception {
137144
new Dsn("http://publicKey:secretKey@/9");

0 commit comments

Comments
 (0)