func TestLowLevel(t *testing.T) { indata := objects.Blob([]byte("TestPostData")) services.PostBlob(indata) blobhcid, err := objects.HcidFromHex( "ca4c4244cee2bd8b8a35feddcd0ba36d775d68637b7f0b4d2558728d0752a2a2", ) b, err := services.GetBlob(blobhcid) if !bytes.Equal(b.Hash(), blobhcid) { t.Fatalf("GetBlob Fail\nExpected: %s\nGot: %s\n", blobhcid, b.Hash()) //Changed } //6dedf7e580671bd90bc9d1f735c75a4f3692b697f8979a147e8edd64fab56e85 testhkid := objects.HkidFromDString( "6523237356270560228617783789728329416595512649112249373497830592"+ "0722414168936112160694238047304378604753005642729767620850685191"+ "88612732562106886379081213385", 10) testCommit := objects.NewCommit(b.Hash(), testhkid) services.PostCommit(testCommit) c, err := services.GetCommit(testhkid) if err != nil { t.Fatalf("Get Commit Fail: %s", err) } else if !bytes.Equal(c.Hkid, testhkid) { t.Fatalf("Expected: %s Got: %s", testhkid, c.Hkid) } else if !c.Verify() { t.Fatalf("Commit Signature Invalid.") } //ede7bec713c93929751f18b1db46d4be3c95286bd5f2d92b9759ff02115dc312 taghkid := objects.HkidFromDString( "4813315537186321970719165779488475377688633084782731170482174374"+ "7256947679650787426167575073363006751150073195493002048627629373"+ "76227751462258339344895829332", 10) lowlvlTag := objects.NewTag( objects.HID(b.Hash()), "blob", "testBlob", nil, taghkid, ) //gen test tag services.PostTag(lowlvlTag) testtag, err := services.GetTag(taghkid, lowlvlTag.NameSegment) if err != nil { t.Fatalf("GetTag Fail. error: %s", err) } else if !bytes.Equal(testtag.Hkid, taghkid) { t.Fatalf("GetTag Fail.\n\t expected: %v\n\t got: %v", taghkid, testtag.Hkid) } else if !testtag.Verify() { t.Fatalf("GetTag Verify Fail") } prikey, err := services.GetKey(taghkid) if err != nil || !bytes.Equal(prikey.Hkid(), taghkid) || !prikey.Verify() { t.Logf("GetKey Fail") t.Fail() } }
func listHelper(h objects.HID, nextPathSegment string, restOfPath string, postBytes objects.Byteser, postType string) (objects.HID, error) { geterr := fmt.Errorf("h in nil") l := objects.List(nil) if h != nil { l, geterr = GetList(h.(objects.HCID)) } posterr := error(nil) if geterr == nil { //update and publish old list nextTypeString, nextHash := l.HashForNamesegment(nextPathSegment) nextPath := restOfPath if nextTypeString == "" { nextTypeString = "list" } if restOfPath == "" { nextTypeString = postType } var hashOfPosted objects.HID if restOfPath == "" && postType != "blob" { hashOfPosted = postBytes.(objects.HKID) //insrt reference by HKID //log.Printf("insrt reference by HKID\n\tnext_path_segment:%s\n\trest_of_path:%s\n", next_path_segment, rest_of_path) } else { hashOfPosted, posterr = post(nextHash, nextPath, nextTypeString, postBytes, postType) //post Data } l.Add(nextPathSegment, hashOfPosted, nextTypeString) } else { //build and publish new list nextHash := objects.HID(nil) nextPath := restOfPath nextTypeString := "list" if restOfPath == "" { nextTypeString = postType } var hashOfPosted objects.HID if restOfPath == "" && postType != "blob" { hashOfPosted = postBytes.(objects.HKID) //insrt reference by HKID //log.Printf("insrt reference by HKID\n\tnext_path_segment:%s\n\trest_of_path:%s\n\t", next_path_segment, rest_of_path) } else { hashOfPosted, posterr = post(nextHash, nextPath, nextTypeString, postBytes, postType) } l = objects.NewList(hashOfPosted, nextTypeString, nextPathSegment) } if posterr != nil { return nil, posterr } err := PostList(l) if err == nil { return l.Hash(), nil } return nil, err }
func tagHelper(h objects.HID, nextPathSegment string, restOfPath string, postBytes objects.Byteser, postType string) (objects.HID, error) { t, geterr := GetTag(h.Bytes(), nextPathSegment) posterr := error(nil) if geterr == nil { //the tag exists with that nameSegment nextTypeString := t.TypeString nextHash := t.HashBytes nextPath := restOfPath var hashOfPosted objects.HID if restOfPath == "" && postType != "blob" { hashOfPosted = objects.HKID(postBytes.Bytes()) //insrt reference by HKID } else { hashOfPosted, posterr = post(nextHash, nextPath, nextTypeString, postBytes, postType) } t = t.Update(hashOfPosted, t.TypeString) } else { //no tag exists with that nameSegment _, err := GetPrivateKeyForHkid(h.(objects.HKID)) if err == nil { //you own the Domain nextHash := objects.HID(nil) nextPath := restOfPath nextTypeString := "list" if restOfPath == "" { nextTypeString = postType } log.Printf("tag pointing to a %s named %s", nextTypeString, nextPathSegment) var hashOfPosted objects.HID if restOfPath == "" && postType != "blob" { hashOfPosted = objects.HKID(postBytes.Bytes()) //insert reference by HKID } else { hashOfPosted, posterr = post(nextHash, nextPath, nextTypeString, postBytes, postType) } t = objects.NewTag(hashOfPosted, nextTypeString, nextPathSegment, nil, h.Bytes()) } else { log.Printf("You don't seem to own this Domain") return nil, fmt.Errorf("You dont own the Domain, meanie") } } if posterr != nil { return nil, posterr } //log.Print(t) err := PostTag(t) if err == nil { return t.Hkid, nil } return nil, err }
func postTag(objHash objects.HCID, tagHkid objects.HKID) { testTagPointingToTestBlob := objects.NewTag( objects.HID(objHash), "blob", "testBlob", nil, tagHkid, ) //gen test tag err := services.PostTag(testTagPointingToTestBlob) //post test tag if err != nil { log.Println(err) } }
func setupForGets() { hkidT := objects.HkidFromDString("39968110670682397993178679825250942322686997267223"+ "4437068973021071131498376777586055610149840018574420844767320660902612889"+ "4016152514163591905578729891874833", 10) //key for commit hkidC := objects.HkidFromDString("4629814823893296480016411334808793836186124559723200"+ "9799621767537249764640887064630013835561124248209118706504211519889067517"+ "10824965155500230480521264034469", 10) //Post blob testBlob := objects.Blob([]byte("testing")) //gen test blob err := services.PostBlob(testBlob) //store test blob if err != nil { log.Println(err) } //post tag testTagPointingToTestBlob := objects.NewTag( objects.HID(testBlob.Hash()), "blob", "testBlob", nil, hkidT, ) //gen test tag err = services.PostTag(testTagPointingToTestBlob) //post test tag if err != nil { log.Println(err) } //post list testListPiontingToTestTag := objects.NewList(testTagPointingToTestBlob.Hkid, "tag", "testTag") //gen test list err = services.PostBlob(testListPiontingToTestTag.Bytes()) //store test list if err != nil { log.Println(err) } // post commit testCommitPointingToTestList := objects.NewCommit(testListPiontingToTestTag.Hash(), hkidC) //gen test commit err = services.PostCommit(testCommitPointingToTestList) //post test commit if err != nil { log.Println(err) } }
func commitHelper(h objects.HKID, path string, postBytes objects.Byteser, postType string) (objects.HID, error) { c, geterr := GetCommit(h) posterr := error(nil) if geterr == nil { //A existing vertion was found nextTypeString := "list" nextHash := c.ListHash nextPath := path var hashOfPosted objects.HID hashOfPosted, posterr = post(nextHash, nextPath, nextTypeString, postBytes, postType) if posterr != nil { return nil, posterr } c = c.Update(hashOfPosted.Bytes()) } else { //A existing vertion was NOT found _, err := GetPrivateKeyForHkid(h) if err == nil { nextHash := objects.HID(nil) nextPath := path nextTypeString := "list" var hashOfPosted objects.HID hashOfPosted, posterr = post(nextHash, nextPath, nextTypeString, postBytes, postType) c = objects.NewCommit(hashOfPosted.Bytes(), h) } else { log.Printf("You don't seem to own this repo\n\th=%v\n\terr=%v\n", h, err) return objects.HKID{}, fmt.Errorf("You don't seem to own this repo") } } if posterr != nil { return nil, posterr } //log.Print(c) err := PostCommit(c) if err == nil { return c.Hkid, nil } return nil, err }
//Post releases a content object and the necessary intermediate objects to storage func Post(objecthash objects.HKID, path string, postBytes objects.Byteser) (hid objects.HID, err error) { hid, err = post(objects.HID(objecthash), path, "commit", postBytes, "blob") return hid, err }