Ejemplo n.º 1
0
func TestCreateAttributesMetadata(t *testing.T) {
	tcert, preK0, err := loadTCertAndPreK0()

	if err != nil {
		t.Error(err)
	}
	tcertRaw := tcert.Raw
	metadata := []byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
	attributeKeys := []string{"position"}
	metadataObjRaw, err := CreateAttributesMetadata(tcertRaw, metadata, preK0, attributeKeys)
	if err != nil {
		t.Error(err)
	}

	var metadataObj pb.AttributesMetadata
	err = proto.Unmarshal(metadataObjRaw, &metadataObj)
	if err != nil {
		t.Error(err)
	}

	if bytes.Compare(metadataObj.Metadata, metadata) != 0 {
		t.Errorf("Invalid metadata result %v but expected %v", metadataObj.Metadata, metadata)
	}

	entries := metadataObj.GetEntries()
	if len(entries) != 2 {
		t.Errorf("Invalid entries in metadata result %v but expected %v", len(entries), 3)
	}

	firstEntry := entries[0]
	if firstEntry.AttributeName != "position" {
		t.Errorf("Invalid first attribute name, this has to be %v but is %v", "position", firstEntry.AttributeName)
	}
	firstKey, err := GetKForAttribute("position", preK0, tcert)
	if err != nil {
		t.Error(err)
	}

	if bytes.Compare(firstKey, firstEntry.AttributeKey) != 0 {
		t.Errorf("Invalid K for first attribute expected %v but returned %v", firstKey, firstEntry.AttributeKey)
	}
}
Ejemplo n.º 2
0
func TestCreateAttributesMetadata_AttributeNotFound(t *testing.T) {
	tcert, preK0, err := loadTCertAndPreK0()

	if err != nil {
		t.Error(err)
	}
	tcertRaw := tcert.Raw
	metadata := []byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}
	attributeKeys := []string{"company"}
	metadataObjRaw, err := CreateAttributesMetadata(tcertRaw, metadata, preK0, attributeKeys)
	if err != nil {
		t.Error(err)
	}

	var metadataObj pb.AttributesMetadata
	err = proto.Unmarshal(metadataObjRaw, &metadataObj)
	if err != nil {
		t.Error(err)
	}
	if bytes.Compare(metadataObj.Metadata, metadata) != 0 {
		t.Errorf("Invalid metadata result %v but expected %v", metadataObj.Metadata, metadata)
	}

	entries := metadataObj.GetEntries()
	if len(entries) != 2 {
		t.Errorf("Invalid entries in metadata result %v but expected %v", len(entries), 3)
	}

	firstEntry := entries[0]
	if firstEntry.AttributeName != "company" {
		t.Errorf("Invalid first attribute name, this has to be %v but is %v", "position", firstEntry.AttributeName)
	}
	_, err = GetKForAttribute("company", preK0, tcert)
	if err == nil {
		t.Fatalf("Test should faild because company is not included within the TCert.")
	}
}