@@ -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" )},
1646
+ {From : path .New ("yaml" , "selinux" , "module" , 0 ), To : path .New ("json" , "systemd" , "units" , 0 )},
1647
+ {From : path .New ("yaml" , "selinux" , "module" , 0 ), To : path .New ("json" , "systemd" , "units" , 0 , "name" )},
1648
+ {From : path .New ("yaml" , "selinux" , "module" , 0 ), To : path .New ("json" , "systemd" , "units" , 0 , "contents" )},
1649
+ {From : path .New ("yaml" , "selinux" , "module" , 0 ), To : path .New ("json" , "systemd" , "units" , 0 , "enabled" )},
1650
+ {From : path .New ("yaml" , "selinux" , "module" , 0 ), To : path .New ("json" , "storage" , "files" )},
1651
+ {From : path .New ("yaml" , "selinux" , "module" , 0 ), To : path .New ("json" , "storage" , "files" , 0 )},
1652
+ {From : path .New ("yaml" , "selinux" , "module" , 0 ), To : path .New ("json" , "storage" , "files" , 0 , "path" )},
1653
+ {From : path .New ("yaml" , "selinux" , "module" , 0 ), To : path .New ("json" , "storage" , "files" , 0 , "append" )},
1654
+ {From : path .New ("yaml" , "selinux" , "module" , 0 ), To : path .New ("json" , "storage" , "files" , 0 , "append" , 0 )},
1655
+ {From : path .New ("yaml" , "selinux" , "module" , 0 ), To : path .New ("json" , "storage" , "files" , 0 , "append" , 0 , "source" )},
1656
+ {From : path .New ("yaml" , "selinux" , "module" , 0 ), To : path .New ("json" , "storage" , "files" , 0 , "append" , 0 , "compression" )},
1657
+ }
1658
+ tests := []struct {
1659
+ in Config
1660
+ out types.Config
1661
+ exceptions []translate.Translation
1662
+ report report.Report
1663
+ }{
1664
+ // config with one module
1665
+ {
1666
+ Config {
1667
+ Selinux : Selinux {
1668
+ Module : []Module {
1669
+ {
1670
+ Name : "some_name" ,
1671
+ Content : "some content here" ,
1672
+ },
1673
+ },
1674
+ },
1675
+ Systemd : Systemd { //how can i write the systemd here if isnt the right config type?
1676
+ Units : []Unit {
1677
+ {
1678
+ Name : "some_name.conf" ,
1679
+ Enabled : util .BoolToPtr (true ),
1680
+ },
1681
+ },
1682
+ },
1683
+ },
1684
+
1685
+ types.Config {
1686
+ Ignition : types.Ignition {
1687
+ Version : "3.5.0-experimental" ,
1688
+ },
1689
+ Storage : types.Storage {
1690
+ Files : []types.File {
1691
+ {
1692
+ Node : types.Node {
1693
+ Path : "/etc/selinux/targeted/modules/active/extra/some_name.cil" ,
1694
+ },
1695
+ FileEmbedded1 : types.FileEmbedded1 {
1696
+ Append : []types.Resource {
1697
+ {
1698
+ Source : util .StrToPtr ("data:,some%20content%20here" ),
1699
+ Compression : util .StrToPtr ("" ),
1700
+ },
1701
+ },
1702
+ },
1703
+ },
1704
+ },
1705
+ },
1706
+ Systemd : types.Systemd {
1707
+ Units : []types.Unit {
1708
+ {
1709
+ Name : "some_name" + ".conf" ,
1710
+ Enabled : util .BoolToPtr (true ),
1711
+ Contents : util .StrToPtr (
1712
+ "[Unit]\n " +
1713
+ "Description=Import SELinux module\n " +
1714
+ "[Service]\n " +
1715
+ "Type=oneshot\n " +
1716
+ "RemainAfterExit=yes\n " +
1717
+ "ExecStart=" + cmdToExecute + "\n " +
1718
+ "[Install]\n " +
1719
+ "WantedBy=multi-user.target\n " ),
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