mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-11-12 14:31:02 +00:00
This patch adds validation to the version pasing logic (parseVersion) to not allow packages to be registered which apt wouldn't accept anyway. It then propogates validation errors through CompareVersions, the way in which parseVersion gets called, so that appropriate decisions can be made. New packages with invalid versions are not accepted. For any pre-exisiting packages with invalid versions, as much care is taken as possible to log warnings, and not use those packages. This PR is loosely bnased on one by by Aaron Foster <afoster@cloudflare.com> though it has largely been written at this point. Signed off with internal and external emails for clarity, but commit is under personal email where we typically do open source contributions from. Signed-off-by: Phil Dibowitz <pdibowitz@cloudflare.com> Signed-off-by: Phil Dibowitz <pdibowitz@ipom.com>
64 lines
1.4 KiB
Go
64 lines
1.4 KiB
Go
package deb
|
|
|
|
import (
|
|
. "gopkg.in/check.v1"
|
|
)
|
|
|
|
type QuerySuite struct {
|
|
}
|
|
|
|
var _ = Suite(&QuerySuite{})
|
|
|
|
func (s *QuerySuite) TestVersionCompare(c *C) {
|
|
q := FieldQuery{"Version", VersionLess, "5.0.0.2", nil}
|
|
|
|
p100 := Package{}
|
|
p100.Version = "5.0.0.100"
|
|
|
|
p1 := Package{}
|
|
p1.Version = "5.0.0.1"
|
|
|
|
c.Check(q.Matches(&p100), Equals, false)
|
|
c.Check(q.Matches(&p1), Equals, true)
|
|
}
|
|
|
|
func (s *QuerySuite) TestVersionCompareGreater(c *C) {
|
|
q := FieldQuery{"Version", VersionGreater, "5.0.0.2", nil}
|
|
|
|
p100 := Package{}
|
|
p100.Version = "5.0.0.100"
|
|
|
|
p1 := Package{}
|
|
p1.Version = "5.0.0.1"
|
|
|
|
c.Check(q.Matches(&p100), Equals, true)
|
|
c.Check(q.Matches(&p1), Equals, false)
|
|
|
|
// invalid version on either side of the comparison must not match
|
|
pInvalid := Package{}
|
|
pInvalid.Version = "1.2.3-"
|
|
c.Check(q.Matches(&pInvalid), Equals, false)
|
|
}
|
|
|
|
func (s *QuerySuite) TestVersionCompareGreaterOrEqual(c *C) {
|
|
q := FieldQuery{"Version", VersionGreaterOrEqual, "5.0.0.2", nil}
|
|
|
|
p100 := Package{}
|
|
p100.Version = "5.0.0.100"
|
|
|
|
pEqual := Package{}
|
|
pEqual.Version = "5.0.0.2"
|
|
|
|
p1 := Package{}
|
|
p1.Version = "5.0.0.1"
|
|
|
|
c.Check(q.Matches(&p100), Equals, true)
|
|
c.Check(q.Matches(&pEqual), Equals, true)
|
|
c.Check(q.Matches(&p1), Equals, false)
|
|
|
|
// invalid version on either side of the comparison must not match
|
|
pInvalid := Package{}
|
|
pInvalid.Version = "1.2.3-"
|
|
c.Check(q.Matches(&pInvalid), Equals, false)
|
|
}
|