Skip to content

Commit bcb16e4

Browse files
committed
dbg: e2e tests
1 parent af58817 commit bcb16e4

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

services/proxy/pkg/middleware/signed_url_auth.go

+16
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ func (m SignedURLAuthenticator) urlIsExpired(query url.Values) (err error) {
144144
}
145145

146146
func (m SignedURLAuthenticator) signatureIsValid(req *http.Request) (err error) {
147+
start := time.Now()
148+
defer func() {
149+
m.Logger.Debug().
150+
Str("duration", time.Since(start).String()).
151+
Str("path", req.URL.Path).
152+
Msg("signature validation completed")
153+
}()
154+
147155
c := revactx.ContextMustGetUser(req.Context())
148156
signingKey, err := m.Store.Read(c.Id.OpaqueId)
149157
if err != nil {
@@ -205,6 +213,14 @@ func (m SignedURLAuthenticator) buildUrlToSign(req *http.Request) string {
205213
}
206214

207215
func (m SignedURLAuthenticator) createSignature(url string, signingKey []byte) string {
216+
start := time.Now()
217+
defer func() {
218+
m.Logger.Debug().
219+
Str("duration", time.Since(start).String()).
220+
Str("url", url).
221+
Msg("signature creation completed")
222+
}()
223+
208224
// the oc10 signature check: $hash = \hash_pbkdf2("sha512", $url, $signingKey, 10000, 64, false);
209225
// - sets the length of the output string to 64
210226
// - sets raw output to false -> if raw_output is FALSE length corresponds to twice the byte-length of the derived key (as every byte of the key is returned as two hexits).

services/proxy/pkg/middleware/signed_url_auth_test.go

+43
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,49 @@ func TestSignedURLAuth_createSignature(t *testing.T) {
158158
}
159159
}
160160

161+
func TestSignedURLAuth_createSignature_executionTime(t *testing.T) {
162+
// Setup test environment
163+
pua := &SignedURLAuthenticator{
164+
PreSignedURLConfig: config.PreSignedURL{
165+
Enabled: true,
166+
},
167+
}
168+
169+
// Create test data
170+
baseURL := "https://example.com/"
171+
signingKey := []byte("somerandomkey")
172+
173+
// Generate random string of length 128
174+
generateRandomString := func(length int) string {
175+
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
176+
b := make([]byte, length)
177+
for i := range b {
178+
b[i] = charset[i%len(charset)]
179+
}
180+
return string(b)
181+
}
182+
183+
N := 100
184+
// Pre-generate random strings to avoid measuring string generation time
185+
randomStrings := make([]string, N)
186+
for i := 0; i < N; i++ {
187+
randomStrings[i] = generateRandomString(128)
188+
}
189+
start := time.Now()
190+
for i := 0; i < N; i++ {
191+
// Simulate download verification
192+
signature := pua.createSignature(baseURL+randomStrings[i], signingKey)
193+
if signature == "" {
194+
t.Fatal("signature creation failed")
195+
}
196+
}
197+
took := time.Since(start)
198+
avg := took.Milliseconds() / int64(N)
199+
// Key iterations: 10000, ~2 ms
200+
// Key iterations: 256*1024, ~73 ms
201+
assert.Less(t, avg, int64(100))
202+
}
203+
161204
func TestSignedURLAuth_validate(t *testing.T) {
162205
nowFunc := func() time.Time {
163206
t, _ := time.Parse(time.RFC3339, "2020-02-02T12:30:00.000Z")

services/webdav/pkg/service/v0/service.go

+5
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,11 @@ func (g Webdav) PublicThumbnailHead(w http.ResponseWriter, r *http.Request) {
467467

468468
func (g Webdav) sendThumbnailResponse(rsp *thumbnailssvc.GetThumbnailResponse, w http.ResponseWriter, r *http.Request) {
469469
logger := g.log.SubloggerWithRequestID(r.Context())
470+
logger.Debug().
471+
Str("endpoint", rsp.DataEndpoint).
472+
Str("transfer_token", rsp.TransferToken).
473+
Msg("initiating download request")
474+
470475
client := &http.Client{
471476
// Timeout: time.Second * 5,
472477
}

0 commit comments

Comments
 (0)