@@ -1637,3 +1637,97 @@ 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" )},
1646
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "files" )},
1647
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "files" , 0 )},
1648
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "files" , 0 , "path" )},
1649
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "files" , 0 , "append" )},
1650
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "files" , 0 , "append" , 0 )},
1651
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "files" , 0 , "append" , 0 , "source" )},
1652
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "storage" , "files" , 0 , "append" , 0 , "compression" )},
1653
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "systemd" , "units" , 0 , "name" )},
1654
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "systemd" , "units" , 0 , "contents" )},
1655
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "systemd" , "units" , 0 , "enabled" )},
1656
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "systemd" , "units" , 0 )},
1657
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "systemd" , "units" )},
1658
+ {From : path .New ("yaml" , "selinux" , "module" ), To : path .New ("json" , "systemd" )},
1659
+ }
1660
+ tests := []struct {
1661
+ in Config
1662
+ out types.Config
1663
+ exceptions []translate.Translation
1664
+ }{
1665
+ // config with one module
1666
+ {
1667
+ Config {
1668
+ Selinux : Selinux {
1669
+ Module : []Module {
1670
+ {
1671
+ Name : "some_name" ,
1672
+ Content : "some content here" ,
1673
+ },
1674
+ },
1675
+ },
1676
+ },
1677
+
1678
+ types.Config {
1679
+ Ignition : types.Ignition {
1680
+ Version : "3.5.0-experimental" ,
1681
+ },
1682
+ Storage : types.Storage {
1683
+ Files : []types.File {
1684
+ {
1685
+ Node : types.Node {
1686
+ Path : "/etc/selinux/targeted/modules/active/extra/some_name.cil" ,
1687
+ },
1688
+ FileEmbedded1 : types.FileEmbedded1 {
1689
+ Append : []types.Resource {
1690
+ {
1691
+ Source : util .StrToPtr ("data:,some%20content%20here" ),
1692
+ Compression : util .StrToPtr ("" ),
1693
+ },
1694
+ },
1695
+ },
1696
+ },
1697
+ },
1698
+ },
1699
+ Systemd : types.Systemd {
1700
+ Units : []types.Unit {
1701
+ {
1702
+ Name : "some_name" + ".conf" ,
1703
+ Enabled : util .BoolToPtr (true ),
1704
+ Contents : util .StrToPtr (
1705
+ "[Unit]\n " +
1706
+ "Description=Import SELinux module\n " +
1707
+ "[Service]\n " +
1708
+ "Type=oneshot\n " +
1709
+ "RemainAfterExit=yes\n " +
1710
+ "ExecStart=" + cmdToExecute + "\n " +
1711
+ "[Install]\n " +
1712
+ "WantedBy=multi-user.target\n " ),
1713
+ },
1714
+ },
1715
+ },
1716
+ },
1717
+ translations ,
1718
+ },
1719
+ }
1720
+
1721
+ for i , test := range tests {
1722
+ t .Run (fmt .Sprintf ("translate %d" , i ), func (t * testing.T ) {
1723
+ out , translations , r := test .in .ToIgn3_5Unvalidated (common.TranslateOptions {})
1724
+ r = confutil .TranslateReportPaths (r , translations )
1725
+ baseutil .VerifyReport (t , test .in , r )
1726
+ assert .Equal (t , test .out , out , "bad output" )
1727
+ assert .Equal (t , report.Report {}, r , "expected empty report" )
1728
+ baseutil .VerifyTranslations (t , translations , test .exceptions )
1729
+ assert .NoError (t , translations .DebugVerifyCoverage (out ), "incomplete TranslationSet coverage" )
1730
+ })
1731
+ }
1732
+
1733
+ }
0 commit comments