satellite/metainfo: store empty useragent in bucket attribution instead of throwing error

Previously, only valid partner IDs could be used for bucket level value attribution. Now that any useragent byte slice can be used, we should allow for empty useragent strings to be stored rather than throwing an error or leaving the bucket with no attribution.

Change-Id: I7043f835588dab1c401a27e31afd74b6b5a3e44b
This commit is contained in:
dlamarmorgan 2021-12-02 09:30:33 -08:00 committed by Damein Morgan
parent 5013dd8a43
commit 3b51eea312
2 changed files with 6 additions and 10 deletions

View File

@ -71,6 +71,9 @@ func (endpoint *Endpoint) ensureAttribution(ctx context.Context, header *pb.Requ
// TrimUserAgent returns userAgentBytes that consist of only the product portion of the user agent, and is bounded by
// the maxUserAgentLength.
func TrimUserAgent(userAgent []byte) ([]byte, error) {
if len(userAgent) == 0 {
return userAgent, nil
}
userAgentEntries, err := useragent.ParseEntries(userAgent)
if err != nil {
return userAgent, Error.New("error while parsing user agent: %w", err)

View File

@ -30,6 +30,8 @@ func TestTrimUserAgent(t *testing.T) {
userAgent []byte
strippedUserAgent []byte
}{
{userAgent: nil, strippedUserAgent: nil},
{userAgent: []byte(""), strippedUserAgent: []byte("")},
{userAgent: []byte("not-a-partner"), strippedUserAgent: []byte("not-a-partner")},
{userAgent: []byte("Zenko"), strippedUserAgent: []byte("Zenko")},
{userAgent: []byte("Zenko uplink/v1.0.0"), strippedUserAgent: []byte("Zenko")},
@ -51,16 +53,6 @@ func TestTrimUserAgent(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, tt.strippedUserAgent, userAgent)
}
for _, tt := range []struct {
userAgent []byte
strippedUserAgent []byte
}{
{userAgent: nil, strippedUserAgent: nil},
{userAgent: []byte(""), strippedUserAgent: []byte("")},
} {
_, err := metainfo.TrimUserAgent(tt.userAgent)
require.Error(t, err)
}
}
func TestBucketAttribution(t *testing.T) {
@ -75,6 +67,7 @@ func TestBucketAttribution(t *testing.T) {
expectedAttribution []byte
}{
{signupPartner: nil, userAgent: nil, expectedAttribution: nil},
{signupPartner: []byte(""), userAgent: []byte(""), expectedAttribution: []byte("")},
{signupPartner: []byte("Minio"), userAgent: nil, expectedAttribution: []byte("Minio")},
{signupPartner: []byte("Minio"), userAgent: []byte("Minio"), expectedAttribution: []byte("Minio")},
{signupPartner: []byte("Minio"), userAgent: []byte("Zenko"), expectedAttribution: []byte("Minio")},