@@ -1637,3 +1637,104 @@ func TestTranslateGrub(t *testing.T) {
1637
1637
})
1638
1638
}
1639
1639
}
1640
+
1641
+ func TestTranslateSelinux (t * testing.T ) {
1642
+ cmdToExecute := "/usr/sbin/semodule -i" + "/etc/selinux/targeted/modules/active/extra/some_name.cil"
1643
+ translations := []translate.Translation {
1644
+ {From : path .New ("yaml" , "version" ), To : path .New ("json" , "ignition" , "version" )},
1645
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "filesystems" )},
1646
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "filesystems" , 0 )},
1647
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "filesystems" , 0 , "path" )},
1648
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "filesystems" , 0 , "device" )},
1649
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "filesystems" , 0 , "format" )},
1650
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" )},
1651
+ {From : path .New ("yaml" , "selinux" , "module" , 0 ), To : path .New ("json" , "systemd" , "units" , 0 )},
1652
+ {From : path .New ("yaml" , "selinux" , "module" , 0 ), To : path .New ("json" , "systemd" , "units" , 0 , "name" )},
1653
+ {From : path .New ("yaml" , "selinux" , "module" , 0 ), To : path .New ("json" , "systemd" , "units" , 0 , "dropins" )},
1654
+ {From : path .New ("yaml" , "selinux" , "module" , 0 ), To : path .New ("json" , "systemd" , "units" , 0 , "dropins" , 0 )},
1655
+ {From : path .New ("yaml" , "selinux" , "module" , 0 ), To : path .New ("json" , "storage" , "files" )},
1656
+ {From : path .New ("yaml" , "selinux" , "module" , 0 ), To : path .New ("json" , "storage" , "files" , 0 )},
1657
+ {From : path .New ("yaml" , "selinux" , "module" , 0 ), To : path .New ("json" , "storage" , "files" , 0 , "path" )},
1658
+ {From : path .New ("yaml" , "selinux" , "module" , 0 ), To : path .New ("json" , "storage" , "files" , 0 , "append" )},
1659
+ {From : path .New ("yaml" , "selinux" , "module" , 0 ), To : path .New ("json" , "storage" , "files" , 0 , "append" , 0 )},
1660
+ {From : path .New ("yaml" , "selinux" , "module" , 0 ), To : path .New ("json" , "storage" , "files" , 0 , "append" , 0 , "source" )},
1661
+ {From : path .New ("yaml" , "selinux" , "module" , 0 ), To : path .New ("json" , "storage" , "files" , 0 , "append" , 0 , "compression" )},
1662
+ }
1663
+ tests := []struct {
1664
+ in Config
1665
+ out types.Config
1666
+ exceptions []translate.Translation
1667
+ report report.Report
1668
+ }{
1669
+ // config with one module
1670
+ {
1671
+ Config {
1672
+ Selinux : Selinux {
1673
+ Module : []Module {
1674
+ {
1675
+ Name : "some_name" ,
1676
+ Content : "some content here" ,
1677
+ },
1678
+ },
1679
+ },
1680
+ },
1681
+ types.Config {
1682
+ Ignition : types.Ignition {
1683
+ Version : "3.5.0-experimental" ,
1684
+ },
1685
+ Systemd : types.Systemd {
1686
+ Units : []types.Unit {
1687
+ {
1688
+
1689
+ Enabled : util .BoolToPtr (true ),
1690
+ Dropins : []types.Dropin {
1691
+ {
1692
+ Name : "some_name.conf" ,
1693
+ Contents : util .StrToPtr (" [Unit]\n " + "Description=Import SELinux module\n " + "[Service]\n " + "Type=oneshot\n " + "RemainAfterExit=no\n " + "ExecStart=" + cmdToExecute + "\n " + "[Install]\n " + "WantedBy=multi-user.target\n " ),
1694
+ },
1695
+ },
1696
+ },
1697
+ },
1698
+ },
1699
+ Storage : types.Storage {
1700
+ Filesystems : []types.Filesystem {
1701
+ {
1702
+ Device : "/dev/disk/by-label/boot" ,
1703
+ Format : util .StrToPtr ("ext4" ),
1704
+ Path : util .StrToPtr ("/boot" ),
1705
+ },
1706
+ },
1707
+ Files : []types.File {
1708
+ {
1709
+ Node : types.Node {
1710
+ Path : "/etc/selinux/targeted/modules/active/extra/some_name.cil" ,
1711
+ },
1712
+ FileEmbedded1 : types.FileEmbedded1 {
1713
+ Append : []types.Resource {
1714
+ {
1715
+ Source : util .StrToPtr ("data:,some%20content%20here" ),
1716
+ Compression : util .StrToPtr ("" ),
1717
+ },
1718
+ },
1719
+ },
1720
+ },
1721
+ },
1722
+ },
1723
+ },
1724
+ translations ,
1725
+ report.Report {},
1726
+ },
1727
+ }
1728
+
1729
+ for i , test := range tests {
1730
+ t .Run (fmt .Sprintf ("translate %d" , i ), func (t * testing.T ) {
1731
+ actual , translations , r := test .in .ToIgn3_5Unvalidated (common.TranslateOptions {})
1732
+ r = confutil .TranslateReportPaths (r , translations )
1733
+ baseutil .VerifyReport (t , test .in , r )
1734
+ assert .Equal (t , test .out , actual , "translation mismatch" )
1735
+ assert .Equal (t , test .report , r , "report mismatch" )
1736
+ baseutil .VerifyTranslations (t , translations , test .exceptions )
1737
+ assert .NoError (t , translations .DebugVerifyCoverage (actual ), "incomplete TranslationSet coverage" )
1738
+ })
1739
+ }
1740
+ }
0 commit comments