Skip to content

Commit

Permalink
these are not the lists you are looking for
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronis committed Jul 25, 2016
1 parent a517f43 commit bdebc7c
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 62 deletions.
16 changes: 4 additions & 12 deletions asserts/device_asserts.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"time"
)

// TODO: model assertion still needs final design review!

// Model holds a model assertion, which is a statement by a brand
// about the properties of a device model.
type Model struct {
Expand Down Expand Up @@ -118,16 +120,6 @@ func assembleModel(assert assertionBase) (Assertion, error) {

// TODO: check 'class' value already here? fundamental policy derives from it

allowedModes, err := checkCommaSepList(assert.headers, "allowed-modes")
if err != nil {
return nil, err
}

requiredSnaps, err := checkCommaSepList(assert.headers, "required-snaps")
if err != nil {
return nil, err
}

timestamp, err := checkRFC3339Date(assert.headers, "timestamp")
if err != nil {
return nil, err
Expand All @@ -136,8 +128,8 @@ func assembleModel(assert assertionBase) (Assertion, error) {
// ignore extra headers and non-empty body for future compatibility
return &Model{
assertionBase: assert,
allowedModes: allowedModes,
requiredSnaps: requiredSnaps,
allowedModes: nil, // XXX: empty for now
requiredSnaps: nil, // XXX: empty for now
timestamp: timestamp,
}, nil
}
Expand Down
7 changes: 2 additions & 5 deletions asserts/device_asserts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ func (mods *modelSuite) TestDecodeOK(c *C) {
c.Check(model.Gadget(), Equals, "brand-gadget")
c.Check(model.Kernel(), Equals, "baz-linux")
c.Check(model.Store(), Equals, "brand-store")
// XXX: these are empty atm
c.Check(model.AllowedModes(), HasLen, 0)
c.Check(model.RequiredSnaps(), DeepEquals, []string{"foo", "bar"})
c.Check(model.RequiredSnaps(), HasLen, 0)
}

const (
Expand Down Expand Up @@ -108,10 +109,6 @@ func (mods *modelSuite) TestDecodeInvalid(c *C) {
{"kernel: baz-linux\n", "kernel: \n", `"kernel" header should not be empty`},
{"store: brand-store\n", "", `"store" header is mandatory`},
{"store: brand-store\n", "store: \n", `"store" header should not be empty`},
{"allowed-modes: \n", "", `"allowed-modes" header is mandatory`},
{"allowed-modes: \n", "allowed-modes: ,\n", `empty entry in comma separated "allowed-modes" header: ","`},
{"required-snaps: foo, bar\n", "", `"required-snaps" header is mandatory`},
{"required-snaps: foo, bar\n", "required-snaps: foo,\n", `empty entry in comma separated "required-snaps" header: "foo,"`},
{"class: fixed\n", "", `"class" header is mandatory`},
{"class: fixed\n", "class: \n", `"class" header should not be empty`},
{mods.tsLine, "", `"timestamp" header is mandatory`},
Expand Down
27 changes: 0 additions & 27 deletions asserts/header_checks.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,30 +112,3 @@ func checkUint(headers map[string]string, name string, bitSize int) (uint64, err
}
return value, nil
}

func checkCommaSepList(headers map[string]string, name string) ([]string, error) {
listStr, ok := headers[name]
if !ok {
return nil, fmt.Errorf("%q header is mandatory", name)
}

// XXX: we likely don't need this much white-space flexibility,
// just supporting newline after , could be enough

// empty lists are allowed
listStr = strings.TrimSpace(listStr)
if listStr == "" {
return nil, nil
}

entries := strings.Split(listStr, ",")
for i, entry := range entries {
entry = strings.TrimSpace(entry)
if entry == "" {
return nil, fmt.Errorf("empty entry in comma separated %q header: %q", name, listStr)
}
entries[i] = entry
}

return entries, nil
}
14 changes: 2 additions & 12 deletions asserts/snap_asserts.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ import (
"time"
)

// TODO: adjust to new designs!

// SnapDeclaration holds a snap-declaration assertion, declaring a
// snap binding its identifying snap-id to a name, asserting its
// publisher and its other properties.
type SnapDeclaration struct {
assertionBase
gates []string
timestamp time.Time
}

Expand All @@ -53,11 +54,6 @@ func (snapdcl *SnapDeclaration) PublisherID() string {
return snapdcl.Header("publisher-id")
}

// Gates returns the list of snap-ids gated by this snap.
func (snapdcl *SnapDeclaration) Gates() []string {
return snapdcl.gates
}

// Timestamp returns the time when the snap-declaration was issued.
func (snapdcl *SnapDeclaration) Timestamp() time.Time {
return snapdcl.timestamp
Expand Down Expand Up @@ -94,19 +90,13 @@ func assembleSnapDeclaration(assert assertionBase) (Assertion, error) {
return nil, err
}

gates, err := checkCommaSepList(assert.headers, "gates")
if err != nil {
return nil, err
}

timestamp, err := checkRFC3339Date(assert.headers, "timestamp")
if err != nil {
return nil, err
}

return &SnapDeclaration{
assertionBase: assert,
gates: gates,
timestamp: timestamp,
}, nil
}
Expand Down
6 changes: 0 additions & 6 deletions asserts/snap_asserts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ func (sds *snapDeclSuite) TestDecodeOK(c *C) {
"snap-id: snap-id-1\n" +
"snap-name: first\n" +
"publisher-id: dev-id1\n" +
"gates: snap-id-3,snap-id-4\n" +
sds.tsLine +
"body-length: 0" +
"\n\n" +
Expand All @@ -67,7 +66,6 @@ func (sds *snapDeclSuite) TestDecodeOK(c *C) {
c.Check(snapDecl.SnapID(), Equals, "snap-id-1")
c.Check(snapDecl.SnapName(), Equals, "first")
c.Check(snapDecl.PublisherID(), Equals, "dev-id1")
c.Check(snapDecl.Gates(), DeepEquals, []string{"snap-id-3", "snap-id-4"})
}

func (sds *snapDeclSuite) TestEmptySnapName(c *C) {
Expand All @@ -77,7 +75,6 @@ func (sds *snapDeclSuite) TestEmptySnapName(c *C) {
"snap-id: snap-id-1\n" +
"snap-name: \n" +
"publisher-id: dev-id1\n" +
"gates: snap-id-3,snap-id-4\n" +
sds.tsLine +
"body-length: 0" +
"\n\n" +
Expand All @@ -99,7 +96,6 @@ func (sds *snapDeclSuite) TestDecodeInvalid(c *C) {
"snap-id: snap-id-1\n" +
"snap-name: first\n" +
"publisher-id: dev-id1\n" +
"gates: snap-id-3,snap-id-4\n" +
sds.tsLine +
"body-length: 0" +
"\n\n" +
Expand All @@ -116,8 +112,6 @@ func (sds *snapDeclSuite) TestDecodeInvalid(c *C) {
{sds.tsLine, "", `"timestamp" header is mandatory`},
{sds.tsLine, "timestamp: \n", `"timestamp" header should not be empty`},
{sds.tsLine, "timestamp: 12:30\n", `"timestamp" header is not a RFC3339 date: .*`},
{"gates: snap-id-3,snap-id-4\n", "", `\"gates\" header is mandatory`},
{"gates: snap-id-3,snap-id-4\n", "gates: foo,\n", `empty entry in comma separated "gates" header: "foo,"`},
}

for _, test := range invalidTests {
Expand Down

0 comments on commit bdebc7c

Please sign in to comment.