Skip to content

Commit 73f98a0

Browse files
authored
[analytics] use dummy static key for untrusted (#17293)
instead of real to unblock Node.js Segment SDK
1 parent 3361d83 commit 73f98a0

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

components/proxy/plugins/analytics/analytics.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import (
2424

2525
const (
2626
moduleName = "gitpod.analytics"
27+
// static key for untrusted segment requests
28+
dummyUntrustedSegmentKey = "untrusted-dummy-key"
2729
)
2830

2931
func init() {
@@ -96,11 +98,9 @@ func (a *Analytics) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddy
9698
a.segmentProxy.ServeHTTP(w, r)
9799
return nil
98100
}
99-
shouldProxyToUntrustedSegment := a.untrustedSegmentKey != "" && (segmentKey == "" || segmentKey == a.untrustedSegmentKey)
101+
shouldProxyToUntrustedSegment := a.untrustedSegmentKey != "" && (segmentKey == "" || segmentKey == dummyUntrustedSegmentKey)
100102
if shouldProxyToUntrustedSegment {
101-
if segmentKey == "" {
102-
r.SetBasicAuth(a.untrustedSegmentKey, "")
103-
}
103+
r.SetBasicAuth(a.untrustedSegmentKey, "")
104104
a.segmentProxy.ServeHTTP(w, r)
105105
return nil
106106
}

components/proxy/plugins/analytics/analytics_test.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,20 @@ func TestServeHTTP(t *testing.T) {
3535
expectedResponseBodyPrefix: "trusted",
3636
},
3737
{
38-
name: "untrusted segment key",
38+
name: "untrusted dummy segment key",
3939
trustedSegmentKey: "trusted-key",
4040
untrustedSegmentKey: "untrusted-key",
41-
providedSegmentKey: "untrusted-key",
41+
providedSegmentKey: dummyUntrustedSegmentKey,
4242
expectedResponseBodyPrefix: "untrusted",
4343
},
44+
{
45+
name: "untrusted segment key",
46+
trustedSegmentKey: "trusted-key",
47+
untrustedSegmentKey: "untrusted-key",
48+
providedSegmentKey: "untrusted-key",
49+
// on purpose to ensure that cliens remove references to untrusted keys
50+
expectedResponseBodyPrefix: "mock",
51+
},
4452
{
4553
name: "empty segment key",
4654
trustedSegmentKey: "trusted-key",
@@ -66,7 +74,7 @@ func TestServeHTTP(t *testing.T) {
6674
name: "only trusted key empty",
6775
trustedSegmentKey: "",
6876
untrustedSegmentKey: "untrusted-key",
69-
providedSegmentKey: "",
77+
providedSegmentKey: dummyUntrustedSegmentKey,
7078
expectedResponseBodyPrefix: "untrusted",
7179
},
7280
{

0 commit comments

Comments
 (0)