satellite/metainfo: remove code for handling partner uuid
Change-Id: I2e0fdc6a23288b3d8e55548f1d97598e48588e4c
This commit is contained in:
parent
19d431ff38
commit
6673125c03
@ -41,7 +41,7 @@ func (endpoint *Endpoint) ensureAttribution(ctx context.Context, header *pb.Requ
|
||||
}
|
||||
}
|
||||
|
||||
partnerID, err := endpoint.ResolvePartnerID(ctx, header, nil)
|
||||
partnerID, err := endpoint.ResolvePartnerID(ctx, header)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -63,19 +63,11 @@ func (endpoint *Endpoint) ensureAttribution(ctx context.Context, header *pb.Requ
|
||||
|
||||
// ResolvePartnerID returns partnerIDBytes as parsed or UUID corresponding to header.UserAgent.
|
||||
// returns empty uuid when neither is defined.
|
||||
func (endpoint *Endpoint) ResolvePartnerID(ctx context.Context, header *pb.RequestHeader, partnerIDBytes []byte) (uuid.UUID, error) {
|
||||
func (endpoint *Endpoint) ResolvePartnerID(ctx context.Context, header *pb.RequestHeader) (uuid.UUID, error) {
|
||||
if header == nil {
|
||||
return uuid.UUID{}, rpcstatus.Error(rpcstatus.InvalidArgument, "header is nil")
|
||||
}
|
||||
|
||||
if len(partnerIDBytes) > 0 {
|
||||
partnerID, err := uuid.FromBytes(partnerIDBytes)
|
||||
if err != nil {
|
||||
return uuid.UUID{}, rpcstatus.Errorf(rpcstatus.InvalidArgument, "unable to parse partner ID: %v", err)
|
||||
}
|
||||
return partnerID, nil
|
||||
}
|
||||
|
||||
if len(header.UserAgent) == 0 {
|
||||
return uuid.UUID{}, nil
|
||||
}
|
||||
|
@ -28,53 +28,42 @@ func TestResolvePartnerID(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// no header
|
||||
_, err = endpoint.ResolvePartnerID(ctx, nil, []byte{1, 2, 3})
|
||||
_, err = endpoint.ResolvePartnerID(ctx, nil)
|
||||
require.Error(t, err)
|
||||
|
||||
// bad uuid
|
||||
_, err = endpoint.ResolvePartnerID(ctx, &pb.RequestHeader{}, []byte{1, 2, 3})
|
||||
require.Error(t, err)
|
||||
|
||||
randomUUID := testrand.UUID()
|
||||
|
||||
// good uuid
|
||||
result, err := endpoint.ResolvePartnerID(ctx, &pb.RequestHeader{}, randomUUID[:])
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, randomUUID, result)
|
||||
|
||||
partnerID, err := endpoint.ResolvePartnerID(ctx, &pb.RequestHeader{
|
||||
UserAgent: []byte("not-a-partner"),
|
||||
}, nil)
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, uuid.UUID{}, partnerID)
|
||||
|
||||
partnerID, err = endpoint.ResolvePartnerID(ctx, &pb.RequestHeader{
|
||||
UserAgent: []byte("Zenko"),
|
||||
}, nil)
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, zenkoPartnerID, partnerID)
|
||||
|
||||
partnerID, err = endpoint.ResolvePartnerID(ctx, &pb.RequestHeader{
|
||||
UserAgent: []byte("Zenko uplink/v1.0.0"),
|
||||
}, nil)
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, zenkoPartnerID, partnerID)
|
||||
|
||||
partnerID, err = endpoint.ResolvePartnerID(ctx, &pb.RequestHeader{
|
||||
UserAgent: []byte("Zenko uplink/v1.0.0 (drpc/v0.10.0 common/v0.0.0-00010101000000-000000000000)"),
|
||||
}, nil)
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, zenkoPartnerID, partnerID)
|
||||
|
||||
partnerID, err = endpoint.ResolvePartnerID(ctx, &pb.RequestHeader{
|
||||
UserAgent: []byte("Zenko uplink/v1.0.0 (drpc/v0.10.0) (common/v0.0.0-00010101000000-000000000000)"),
|
||||
}, nil)
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, zenkoPartnerID, partnerID)
|
||||
|
||||
partnerID, err = endpoint.ResolvePartnerID(ctx, &pb.RequestHeader{
|
||||
UserAgent: []byte("uplink/v1.0.0 (drpc/v0.10.0 common/v0.0.0-00010101000000-000000000000)"),
|
||||
}, nil)
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, uuid.UUID{}, partnerID)
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user