Skip to content

Commit

Permalink
asserts: add missing systemUserFormatAnalyze() (thanks Samuele)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvo5 committed Jun 15, 2020
1 parent ed6f0c2 commit 50a2d9d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions asserts/asserts.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ func MockMaxSupportedFormat(assertType *AssertionType, maxFormat int) (restore f

var formatAnalyzer = map[*AssertionType]func(headers map[string]interface{}, body []byte) (formatnum int, err error){
SnapDeclarationType: snapDeclarationFormatAnalyze,
SystemUserType: systemUserFormatAnalyze,
}

// MaxSupportedFormats returns a mapping between assertion type names
Expand Down
14 changes: 14 additions & 0 deletions asserts/system_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,17 @@ func assembleSystemUser(assert assertionBase) (Assertion, error) {
forcePasswordChange: forcePasswordChange,
}, nil
}

func systemUserFormatAnalyze(headers map[string]interface{}, body []byte) (formatnum int, err error) {
formatnum = 0

serials, err := checkStringList(headers, "serials")
if err != nil {
return 0, err
}
if len(serials) > 0 {
formatnum = 1
}

return formatnum, nil
}
14 changes: 14 additions & 0 deletions asserts/system_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,17 @@ func (s *systemUserSuite) TestDecodeOKFormat1(c *C) {
c.Check(systemUser.Serials(), DeepEquals, []string{"7c7f435d-ed28-4281-bd77-e271e0846904"})

}

func (s *systemUserSuite) TestSuggestedFormat(c *C) {
fmtnum, err := asserts.SuggestFormat(asserts.SystemUserType, nil, nil)
c.Assert(err, IsNil)
c.Check(fmtnum, Equals, 0)

headers := map[string]interface{}{
"serials": []interface{}{"serialserial"},
}
fmtnum, err = asserts.SuggestFormat(asserts.SystemUserType, headers, nil)
c.Assert(err, IsNil)
c.Check(fmtnum, Equals, 1)

}

0 comments on commit 50a2d9d

Please sign in to comment.