@@ -1497,24 +1497,31 @@ func TestLintBlueprint(t *testing.T) {
14971497 }))
14981498
14991499 cases := []struct {
1500- blueprint v1.BlueprintBody
1501- lintErrors []v1.BlueprintLintItem
1500+ name string
1501+ blueprint v1.BlueprintBody
1502+ snapshot * json.RawMessage
1503+ lintErrors []v1.BlueprintLintItem
1504+ lintWarnings []v1.BlueprintLintItem
15021505 }{
15031506 {
1507+ name : "missing packages and services" ,
15041508 blueprint : v1.BlueprintBody {
15051509 Distribution : "rhel-8" ,
15061510 Customizations : v1.Customizations {
15071511 Openscap : & oscap ,
15081512 },
15091513 },
1514+ snapshot : nil ,
15101515 lintErrors : []v1.BlueprintLintItem {
15111516 {Name : "Compliance" , Description : "package required-by-compliance required by policy is not present" },
15121517 {Name : "Compliance" , Description : "service enabled-required-by-compliance required as enabled by policy is not present" },
15131518 {Name : "Compliance" , Description : "service masked-required-by-compliance required as masked by policy is not present" },
15141519 {Name : "Compliance" , Description : "FIPS required 'true' by policy but not set" },
15151520 },
1521+ lintWarnings : []v1.BlueprintLintItem {},
15161522 },
15171523 {
1524+ name : "all requirements satisfied" ,
15181525 blueprint : v1.BlueprintBody {
15191526 Distribution : "rhel-8" ,
15201527 Customizations : v1.Customizations {
@@ -1535,22 +1542,28 @@ func TestLintBlueprint(t *testing.T) {
15351542 },
15361543 },
15371544 },
1538- lintErrors : []v1.BlueprintLintItem {},
1545+ snapshot : nil ,
1546+ lintErrors : []v1.BlueprintLintItem {},
1547+ lintWarnings : []v1.BlueprintLintItem {},
15391548 },
15401549 {
1550+ name : "missing filesystems and kernel params" ,
15411551 blueprint : v1.BlueprintBody {
15421552 Distribution : "rhel-8" ,
15431553 Customizations : v1.Customizations {
15441554 Openscap : & oscap2 ,
15451555 },
15461556 },
1557+ snapshot : nil ,
15471558 lintErrors : []v1.BlueprintLintItem {
15481559 {Name : "Compliance" , Description : "mountpoint /tmp required by policy is not present" },
15491560 {Name : "Compliance" , Description : "mountpoint /var required by policy is not present" },
15501561 {Name : "Compliance" , Description : "kernel command line parameter '-compliance' required by policy not set" },
15511562 },
1563+ lintWarnings : []v1.BlueprintLintItem {},
15521564 },
15531565 {
1566+ name : "filesystems and kernel params satisfied" ,
15541567 blueprint : v1.BlueprintBody {
15551568 Distribution : "rhel-8" ,
15561569 Customizations : v1.Customizations {
@@ -1570,57 +1583,130 @@ func TestLintBlueprint(t *testing.T) {
15701583 },
15711584 },
15721585 },
1573- lintErrors : []v1.BlueprintLintItem {},
1586+ snapshot : nil ,
1587+ lintErrors : []v1.BlueprintLintItem {},
1588+ lintWarnings : []v1.BlueprintLintItem {},
15741589 },
15751590 {
1591+ name : "unsupported minor version" ,
15761592 blueprint : v1.BlueprintBody {
15771593 Distribution : "rhel-89" ,
15781594 Customizations : v1.Customizations {
15791595 Openscap : & oscap2 ,
15801596 },
15811597 },
1598+ snapshot : nil ,
15821599 lintErrors : []v1.BlueprintLintItem {
15831600 {Name : "Compliance" , Description : "Compliance policy does not have a definition for the latest minor version" },
15841601 },
1602+ lintWarnings : []v1.BlueprintLintItem {},
15851603 },
15861604 {
1605+ name : "unsupported minor version duplicate" ,
15871606 blueprint : v1.BlueprintBody {
15881607 Distribution : "rhel-89" ,
15891608 Customizations : v1.Customizations {
15901609 Openscap : & oscap2 ,
15911610 },
15921611 },
1612+ snapshot : nil ,
15931613 lintErrors : []v1.BlueprintLintItem {
15941614 // this error is unfixable for now
15951615 {Name : "Compliance" , Description : "Compliance policy does not have a definition for the latest minor version" },
15961616 },
1617+ lintWarnings : []v1.BlueprintLintItem {},
15971618 },
15981619 {
1620+ name : "minimal policy missing package" ,
15991621 blueprint : v1.BlueprintBody {
16001622 Distribution : "rhel-8" ,
16011623 Customizations : v1.Customizations {
16021624 Openscap : & oscap3 ,
16031625 },
16041626 },
1627+ snapshot : nil ,
16051628 lintErrors : []v1.BlueprintLintItem {
16061629 {Name : "Compliance" , Description : "package required-by-compliance required by policy is not present" },
16071630 },
1631+ lintWarnings : []v1.BlueprintLintItem {},
1632+ },
1633+ {
1634+ name : "policy changes generate warnings" ,
1635+ blueprint : v1.BlueprintBody {
1636+ Distribution : "rhel-8" ,
1637+ Customizations : v1.Customizations {
1638+ Openscap : & oscap3 , // Minimal policy - only requires "required-by-compliance" package
1639+ Packages : & []string {
1640+ "required-by-compliance" , // Still required by minimal policy
1641+ },
1642+ },
1643+ },
1644+ snapshot : func () * json.RawMessage {
1645+ // Create snapshot with previous policy's customizations (more than current policy requires)
1646+ snapshotData := map [string ]interface {}{
1647+ "compliance" : map [string ]interface {}{
1648+ "policy_id" : mocks .PolicyID , // Previous policy was the full one
1649+ "policy_customizations" : map [string ]interface {}{
1650+ "packages" : []string {"required-by-compliance" , "obsolete-package" },
1651+ "services" : map [string ]interface {}{
1652+ "enabled" : []string {"enabled-required-by-compliance" , "obsolete-enabled-service" },
1653+ "masked" : []string {"masked-required-by-compliance" , "obsolete-masked-service" },
1654+ "disabled" : []string {"obsolete-disabled-service" },
1655+ },
1656+ "filesystem" : []map [string ]interface {}{
1657+ {"mountpoint" : "/tmp" , "min_size" : 1000 },
1658+ {"mountpoint" : "/obsolete" , "min_size" : 500 },
1659+ },
1660+ "kernel" : map [string ]interface {}{
1661+ "name" : "obsolete-kernel" ,
1662+ "append" : "obsolete-param=1" ,
1663+ },
1664+ "fips" : map [string ]interface {}{
1665+ "enabled" : true ,
1666+ },
1667+ },
1668+ },
1669+ }
1670+ data , _ := json .Marshal (snapshotData )
1671+ rawMsg := json .RawMessage (data )
1672+ return & rawMsg
1673+ }(),
1674+ lintErrors : []v1.BlueprintLintItem {},
1675+ lintWarnings : []v1.BlueprintLintItem {
1676+ {Name : "Compliance" , Description : "package obsolete-package is no longer required by policy" },
1677+ {Name : "Compliance" , Description : "service enabled-required-by-compliance is no longer required as enabled by policy" },
1678+ {Name : "Compliance" , Description : "service obsolete-enabled-service is no longer required as enabled by policy" },
1679+ {Name : "Compliance" , Description : "service masked-required-by-compliance is no longer required as masked by policy" },
1680+ {Name : "Compliance" , Description : "service obsolete-masked-service is no longer required as masked by policy" },
1681+ {Name : "Compliance" , Description : "service obsolete-disabled-service is no longer required as disabled by policy" },
1682+ {Name : "Compliance" , Description : "mountpoint /tmp is no longer required by policy" },
1683+ {Name : "Compliance" , Description : "mountpoint /obsolete is no longer required by policy" },
1684+ {Name : "Compliance" , Description : "kernel name obsolete-kernel is no longer required by policy" },
1685+ {Name : "Compliance" , Description : "kernel command line parameter 'obsolete-param=1' is no longer required by policy" },
1686+ {Name : "Compliance" , Description : "FIPS is no longer required by policy" },
1687+ },
16081688 },
16091689 }
16101690
16111691 for idx , c := range cases {
1612- fmt .Printf ("TestLintBlueprint case %d\n " , idx )
1692+ fmt .Printf ("TestLintBlueprint case %d: %s \n " , idx , c . name )
16131693
16141694 bpID := uuid .New ()
16151695 bpjson , err := json .Marshal (c .blueprint )
16161696 require .NoError (t , err )
1617- require .NoError (t , srv .DB .InsertBlueprint (context .Background (), bpID , uuid .New (), "000000" , "000000" , "bp1" , "" , bpjson , nil , nil ))
1697+
1698+ var snapshotBytes []byte
1699+ if c .snapshot != nil {
1700+ snapshotBytes = []byte (* c .snapshot )
1701+ }
1702+ require .NoError (t , srv .DB .InsertBlueprint (context .Background (), bpID , uuid .New (), "000000" , "000000" , "bp1" , "" , bpjson , nil , snapshotBytes ))
16181703
16191704 var result v1.BlueprintResponse
16201705 respStatusCode , body := tutils .GetResponseBody (t , fmt .Sprintf ("%s/api/image-builder/v1/blueprints/%s" , srv .URL , bpID ), & tutils .AuthString0 )
16211706 require .Equal (t , http .StatusOK , respStatusCode )
16221707 require .NoError (t , json .Unmarshal ([]byte (body ), & result ))
16231708 require .ElementsMatch (t , c .lintErrors , result .Lint .Errors )
1709+ require .ElementsMatch (t , c .lintWarnings , result .Lint .Warnings )
16241710
16251711 require .NoError (t , srv .DB .DeleteBlueprint (context .Background (), bpID , "000000" ))
16261712 }
0 commit comments