2013-10-22 05:08:45 +00:00
|
|
|
/*
|
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
|
|
|
Copyright 2013 The Perkeep Authors
|
2013-10-22 05:08:45 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package schema
|
|
|
|
|
|
|
|
import (
|
2017-03-29 18:46:37 +00:00
|
|
|
"encoding/json"
|
2013-10-22 05:08:45 +00:00
|
|
|
"strings"
|
|
|
|
"testing"
|
2017-03-29 18:46:37 +00:00
|
|
|
"time"
|
2013-10-22 05:08:45 +00:00
|
|
|
|
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
|
|
|
"perkeep.org/pkg/blob"
|
|
|
|
"perkeep.org/pkg/jsonsign"
|
2013-10-22 05:08:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestSigner(t *testing.T) {
|
|
|
|
if testing.Short() {
|
|
|
|
t.Skip("skipping in short mode")
|
|
|
|
}
|
|
|
|
ent, err := jsonsign.NewEntity()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
armorPub, err := jsonsign.ArmoredPublicKey(ent)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-01-09 23:07:38 +00:00
|
|
|
pubRef := blob.RefFromString(armorPub)
|
2013-10-22 05:08:45 +00:00
|
|
|
sig, err := NewSigner(pubRef, strings.NewReader(armorPub), ent)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("NewSigner: %v", err)
|
|
|
|
}
|
2018-01-16 23:03:16 +00:00
|
|
|
pn, err := NewUnsignedPermanode().Sign(ctxbg, sig)
|
2013-10-22 05:08:45 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("NewPermanode: %v", err)
|
|
|
|
}
|
|
|
|
if !strings.Contains(pn, `,"camliSig":"`) {
|
|
|
|
t.Errorf("Permanode doesn't look signed: %v", pn)
|
|
|
|
}
|
|
|
|
}
|
2017-03-29 18:46:37 +00:00
|
|
|
|
|
|
|
// TestClaimDate makes sure that when we sign a schema, we set the claimDate to
|
|
|
|
// the time of the signature.
|
|
|
|
// It demonstrates that issue #917 is fixed.
|
|
|
|
func TestClaimDate(t *testing.T) {
|
|
|
|
ent, err := jsonsign.NewEntity()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
armorPub, err := jsonsign.ArmoredPublicKey(ent)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2018-01-09 23:07:38 +00:00
|
|
|
pubRef := blob.RefFromString(armorPub)
|
2017-03-29 18:46:37 +00:00
|
|
|
sig, err := NewSigner(pubRef, strings.NewReader(armorPub), ent)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("NewSigner: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
sigTime, err := time.Parse(time.RFC3339, "2006-01-02T15:04:05Z")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
share := NewShareRef(ShareHaveRef, true).SetShareTarget(pubRef)
|
2018-01-16 23:03:16 +00:00
|
|
|
signed, err := share.SignAt(ctxbg, sig, sigTime)
|
2017-03-29 18:46:37 +00:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
ss := &superset{}
|
|
|
|
if err := json.NewDecoder(strings.NewReader(signed)).Decode(ss); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if !strings.HasPrefix(ss.ClaimDate.String(), "2006-01-02") {
|
|
|
|
t.Fatalf("wrong claimDate in superset: got %q, wanted %q", ss.ClaimDate, sigTime)
|
|
|
|
}
|
|
|
|
}
|