Exemplo n.º 1
0
func TestDecodeLinkTicketShouldErrorBrokenProto(t *testing.T) {
	str := "broken"
	_, err := replication.DecodeLinkTicket(str)
	if err == nil {
		t.Errorf("DecodeLinkTicket(%q) = _, <nil>; want error", str)
	}
}
Exemplo n.º 2
0
func TestDecodeLinkTicketBasic(t *testing.T) {
	ticket := &replication.ServiceLinkTicket{
		PrimaryId:   proto.String("dummyid"),
		PrimaryUrl:  proto.String("http://dummy"),
		GeneratedBy: proto.String("dummy"),
		Ticket:      []byte("dummyticket"),
	}
	m, err := proto.Marshal(ticket)
	if err != nil {
		t.Fatalf("proto.Marshal()=%q,_; want <nil>", err)
	}
	str := encodeAndTrimEqual(m)
	dec, err := replication.DecodeLinkTicket(str)
	if err != nil {
		t.Errorf("DecodeLinkTicket(%q) = _, %q; want <nil>", str, err)
	}
	if !reflect.DeepEqual(ticket, dec) {
		t.Errorf("DecodeLinkTicket(%q) = %q; want %q", str, proto.MarshalTextString(dec), proto.MarshalTextString(ticket))
	}
}
Exemplo n.º 3
0
func TestDecodeLinkTicketShouldHandleWebSafeBase64(t *testing.T) {
	ticket := &replication.ServiceLinkTicket{
		PrimaryId:   proto.String("dummyid"),
		PrimaryUrl:  proto.String("http://dummy"),
		GeneratedBy: proto.String("dummy"),
		Ticket:      []byte("dummyticket"),
	}
	m, err := proto.Marshal(ticket)
	if err != nil {
		t.Fatalf("proto.Marshal()=%q,_; want <nil>", err)
	}
	testValue := base64.StdEncoding.EncodeToString(m)
	if !strings.HasSuffix(testValue, "=") {
		t.Fatalf("ticket is not expected pattern %q. this test is meaningless without padding", testValue)
	}
	str := encodeAndTrimEqual(m)
	dec, err := replication.DecodeLinkTicket(str)
	if err != nil {
		t.Errorf("DecodeLinkTicket(%q) = _, %q; want <nil>", str, err)
	}
	if !reflect.DeepEqual(ticket, dec) {
		t.Errorf("DecodeLinkTicket(%q) = %q; want %q", str, proto.MarshalTextString(dec), proto.MarshalTextString(ticket))
	}
}