Skip to content

Commit

Permalink
fixes and more testing, limit filename length some more
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanHCB committed Apr 9, 2022
1 parent 36bb0ff commit 3a0a6bd
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
4 changes: 2 additions & 2 deletions implementation/caching/caching.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ func (c *CachingImpl) Perform(ctx context.Context, method string, requestUrl str
response.Status = cachedResponse.ResponseStatus
if err == nil && err2 == nil {
// cache successfully used
aulogging.Logger.Ctx(ctx).Info().Printf("downstream %s (%s) -> %d cached %d seconds ago", method, requestUrl, response.Status, age.Milliseconds()/1000)
aulogging.Logger.Ctx(ctx).Info().Printf("downstream %s %s -> %d cached %d seconds ago", method, requestUrl, response.Status, age.Milliseconds()/1000)
return nil
} else {
// invalid cache entry -- delete
aulogging.Logger.Ctx(ctx).Warn().WithErr(err).Printf("downstream %s (%s) -> %d cache FAIL, see error -- deleting cache entry", method, requestUrl, response.Status)
aulogging.Logger.Ctx(ctx).Warn().WithErr(err).Printf("downstream %s %s -> %d cache FAIL, see error -- deleting cache entry", method, requestUrl, response.Status)
c.Cache.Delete(key)
}
} else {
Expand Down
3 changes: 3 additions & 0 deletions implementation/recorder/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ func ConstructFilename(method string, requestUrl string) (string, error) {

m := strings.ToLower(method)
p := url.QueryEscape(parsedUrl.EscapedPath())
if len(p) > 120 {
p = string([]byte(p)[:120])
}
// we have to ensure the filenames don't get too long. git for windows only supports 260 character paths
md5sumOverQuery := md5.Sum([]byte(parsedUrl.RawQuery))
q := hex.EncodeToString(md5sumOverQuery[:])
Expand Down
22 changes: 22 additions & 0 deletions implementation/recorder/recorder_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package aurestrecorder

import (
"github.com/stretchr/testify/require"
"testing"
)

func TestConstructFilenameLong(t *testing.T) {
requestUrl := "https://some.super.long.server.name.that.hopefully.does.not.exist/api/rest/v1/v2/v3/v4/this/is/intentionally/very/very/very/very/long/djkfjhdalsfhdsahjflkdjsahfkjlsdhafjkdshafkjlsdahf/asdfjkldsahfkjlfad/dskjfhjkdsfahlk/sdafjkhsdafklhreuih/dfgjgkjlhgjlkhg?asjdfhlkhewuirfhkjsdhlk=kjhrelrukihsjd&fsdkjhfdjklhsdf=werjkyewuiryuweiry&sfuyfddsjkhjkldsfhldkfs=sdjhdflksjhfdhsf"
actual, err := ConstructFilename("GET", requestUrl)
expected := "request_get_%2Fapi%2Frest%2Fv1%2Fv2%2Fv3%2Fv4%2Fthis%2Fis%2Fintentionally%2Fvery%2Fvery%2Fvery%2Fvery%2Flong%2Fdjkfjhdalsfhdsahjflkd_fb2e3656d88910ffc49023f99f5e0df6.json"
require.Nil(t, err)
require.Equal(t, expected, actual)
}

func TestConstructFilenameShort(t *testing.T) {
requestUrl := "https://some.short.server.name/api/rest/v1/kittens"
actual, err := ConstructFilename("GET", requestUrl)
expected := "request_get_%2Fapi%2Frest%2Fv1%2Fkittens_d41d8cd98f00b204e9800998ecf8427e.json"
require.Nil(t, err)
require.Equal(t, expected, actual)
}
2 changes: 1 addition & 1 deletion implementation/requestlogging/requestlogging.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func New(wrapped aurestclientapi.Client) aurestclientapi.Client {
}

func (c *RequestLoggingImpl) Perform(ctx context.Context, method string, requestUrl string, requestBody interface{}, response *aurestclientapi.ParsedResponse) error {
aulogging.Logger.Ctx(ctx).Debug().Printf("downstream %s (%s)...", method, requestUrl)
aulogging.Logger.Ctx(ctx).Debug().Printf("downstream %s %s...", method, requestUrl)
before := time.Now()
err := c.Wrapped.Perform(ctx, method, requestUrl, requestBody, response)
millis := time.Now().Sub(before).Milliseconds()
Expand Down

0 comments on commit 3a0a6bd

Please sign in to comment.