diff options
Diffstat (limited to 'src/core/settings/plugins/ifcfg-rh/tests')
215 files changed, 14478 insertions, 0 deletions
diff --git a/src/core/settings/plugins/ifcfg-rh/tests/meson.build b/src/core/settings/plugins/ifcfg-rh/tests/meson.build new file mode 100644 index 00000000..077e4782 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/meson.build @@ -0,0 +1,16 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later + +exe = executable( + 'test-ifcfg-rh', + 'test-ifcfg-rh.c', + dependencies: libNetworkManagerTest_dep, + c_args: test_c_flags, + link_with: libnms_ifcfg_rh_core, +) + +test( + 'ifcfg-rh/test-ifcfg-rh', + test_script, + timeout: 90, + args: test_args + [exe.full_path()], +) diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-System_test-bridge-component-a.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-System_test-bridge-component-a.cexpected new file mode 100644 index 00000000..d81d9187 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-System_test-bridge-component-a.cexpected @@ -0,0 +1,8 @@ +HWADDR=00:22:15:59:62:97 +TYPE=Ethernet +BRIDGING_OPTS="priority=28 hairpin_mode=1" +NAME="System test-bridge-component" +UUID=${UUID} +DEVICE=eth0 +ONBOOT=no +BRIDGE=br0 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-System_test-bridge-component-b.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-System_test-bridge-component-b.cexpected new file mode 100644 index 00000000..2e69c5e7 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-System_test-bridge-component-b.cexpected @@ -0,0 +1,16 @@ +HWADDR=00:22:15:59:62:97 +TYPE=Ethernet +NAME="System test-bridge-component" +UUID=${UUID} +DEVICE=eth0 +ONBOOT=no +PROXY_METHOD=none +BROWSER_ONLY=no +BOOTPROTO=dhcp +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6INIT=yes +IPV6_AUTOCONF=yes +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no +IPV6_ADDR_GEN_MODE=stable-privacy diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-System_test-wired-802-1X-subj-matches.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-System_test-wired-802-1X-subj-matches.cexpected new file mode 100644 index 00000000..59a6f79b --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-System_test-wired-802-1X-subj-matches.cexpected @@ -0,0 +1,22 @@ +HWADDR=00:11:22:33:44:EE +TYPE=Ethernet +KEY_MGMT=IEEE8021X +IEEE_8021X_EAP_METHODS=PEAP +IEEE_8021X_IDENTITY="Jara Cimrman" +IEEE_8021X_PASSWORD_FLAGS="user ask" +IEEE_8021X_PEAP_VERSION=1 +IEEE_8021X_INNER_AUTH_METHODS=GTC +IEEE_8021X_SUBJECT_MATCH=server1.yourdomain.tld +IEEE_8021X_PHASE2_SUBJECT_MATCH=server2.yourdomain.tld +IEEE_8021X_ALTSUBJECT_MATCHES="a.yourdomain.tld b.yourdomain.tld c.yourdomain.tld" +IEEE_8021X_PHASE2_ALTSUBJECT_MATCHES="x.yourdomain.tld y.yourdomain.tld" +PROXY_METHOD=none +BROWSER_ONLY=no +BOOTPROTO=dhcp +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6INIT=no +NAME="System test-wired-802-1X-subj-matches" +UUID=${UUID} +DEVICE=eth0 +ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_User_1.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_User_1.cexpected new file mode 100644 index 00000000..a48be78a --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_User_1.cexpected @@ -0,0 +1,34 @@ +TYPE=Ethernet +PROXY_METHOD=none +BROWSER_ONLY=no +NM_USER__M_Y___053=val=MY.+ +NM_USER__M_Y___055=val=MY.- +NM_USER__M_Y___057=val=MY./ +NM_USER__M_Y__8_053_V=val=MY.8+V +NM_USER__M_Y__8_055_V=val=MY.8-V +NM_USER__M_Y__8_057_V=val=MY.8/V +NM_USER__M_Y__8_075_V=val=MY.8=V +NM_USER__M_Y__8_V=val=MY.8V +NM_USER__M_Y__8_137_V=val=MY.8_V +NM_USER__M_Y___075=val=MY.= +NM_USER__M_Y___A_V=val=MY.AV +NM_USER__M_Y___137=val=MY._ +NM_USER_MY___AV=val=my.Av +NM_USER_MY___137V=val=my._v +NM_USER_MY__KEYS__1=val=my.keys.1 +NM_USER_MY__OTHER___K_E_Y__42=val=my.other.KEY.42 +NM_USER_MY__V_053=val=my.v+ +NM_USER_MY__V_137_137AL3=val=my.v__al3 +NM_USER_MY__VAL1= +NM_USER_MY__VAL2=val=my.val2 +BOOTPROTO=dhcp +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6INIT=yes +IPV6_AUTOCONF=yes +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no +IPV6_ADDR_GEN_MODE=stable-privacy +NAME="Test User 1" +UUID=${UUID} +ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Bond_Main.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Bond_Main.cexpected new file mode 100644 index 00000000..b288c04a --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Bond_Main.cexpected @@ -0,0 +1,17 @@ +BONDING_OPTS="mode=balance-rr downdelay=5 miimon=100 updelay=10" +TYPE=Bond +BONDING_MASTER=yes +HWADDR= +PROXY_METHOD=none +BROWSER_ONLY=no +BOOTPROTO=none +IPADDR=1.1.1.3 +PREFIX=24 +GATEWAY=1.1.1.1 +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6INIT=no +NAME="Test Write Bond Main" +UUID=${UUID} +DEVICE=bond0 +ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Bridge_Component.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Bridge_Component.cexpected new file mode 100644 index 00000000..a8ff8df3 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Bridge_Component.cexpected @@ -0,0 +1,9 @@ +HWADDR=31:33:33:37:BE:CD +MTU=1492 +TYPE=Ethernet +BRIDGING_OPTS="priority=50 path_cost=33" +BRIDGE_PORT_VLANS="1 untagged,2 pvid,4-4094 untagged" +NAME="Test Write Bridge Component" +UUID=${UUID} +ONBOOT=yes +BRIDGE=br0 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Permissions.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Permissions.cexpected new file mode 100644 index 00000000..80e96921 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Permissions.cexpected @@ -0,0 +1,11 @@ +TYPE=Ethernet +PROXY_METHOD=none +BROWSER_ONLY=no +BOOTPROTO=dhcp +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6INIT=no +NAME="Test Write Permissions" +UUID=${UUID} +ONBOOT=yes +USERS="blahblah foobar asdfasdf" diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Proxy_Basic.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Proxy_Basic.cexpected new file mode 100644 index 00000000..716eedc2 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Proxy_Basic.cexpected @@ -0,0 +1,15 @@ +TYPE=Ethernet +PROXY_METHOD=auto +PAC_URL=https://wpad.neverland.org/wpad.dat +BROWSER_ONLY=no +BOOTPROTO=dhcp +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6INIT=yes +IPV6_AUTOCONF=yes +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no +IPV6_ADDR_GEN_MODE=stable-privacy +NAME="Test Write Proxy Basic" +UUID=${UUID} +ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Routing_Rules.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Routing_Rules.cexpected new file mode 100644 index 00000000..0c2fa035 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Routing_Rules.cexpected @@ -0,0 +1,19 @@ +TYPE=Ethernet +PROXY_METHOD=none +BROWSER_ONLY=no +BOOTPROTO=dhcp +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6INIT=yes +IPV6_AUTOCONF=yes +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no +IPV6_ADDR_GEN_MODE=stable-privacy +ROUTING_RULE_1="priority 10 from 0.0.0.0/0 table 1" +ROUTING_RULE_2="priority 10 to 192.167.8.0/24 table 2" +ROUTING_RULE6_3="priority 10 from ::/0 table 10" +ROUTING_RULE6_4="priority 10 to 1:2:3::5/24 table 22" +ROUTING_RULE6_5="priority 10 to 1:3:3::5 table 55" +NAME="Test Write Routing Rules" +UUID=${UUID} +ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Team_Infiniband_Port.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Team_Infiniband_Port.cexpected new file mode 100644 index 00000000..2df1fbb3 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Team_Infiniband_Port.cexpected @@ -0,0 +1,9 @@ +CONNECTED_MODE=no +TYPE=InfiniBand +TEAM_PORT_CONFIG="{\"inf1\": {\"prio\": -10, \"sticky\": true}}" +NAME="Test Write Team Infiniband Port" +UUID=${UUID} +DEVICE=inf1 +ONBOOT=yes +TEAM_MASTER=team0 +DEVICETYPE=TeamPort diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Team_Port.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Team_Port.cexpected new file mode 100644 index 00000000..ff55cefe --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Team_Port.cexpected @@ -0,0 +1,6 @@ +TEAM_PORT_CONFIG="{\"p4p1\": {\"prio\": -10, \"sticky\": true}}" +NAME="Test Write Team Port" +UUID=${UUID} +ONBOOT=yes +TEAM_MASTER=team0 +DEVICETYPE=TeamPort diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_VLAN_reorder_hdr.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_VLAN_reorder_hdr.cexpected new file mode 100644 index 00000000..9c2a1ff0 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_VLAN_reorder_hdr.cexpected @@ -0,0 +1,21 @@ +VLAN=yes +TYPE=Vlan +PHYSDEV=eth0 +VLAN_ID=444 +REORDER_HDR=yes +GVRP=no +MVRP=no +HWADDR= +PROXY_METHOD=none +BROWSER_ONLY=no +BOOTPROTO=dhcp +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6INIT=yes +IPV6_AUTOCONF=yes +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no +IPV6_ADDR_GEN_MODE=stable-privacy +NAME="Test Write VLAN reorder_hdr" +UUID=${UUID} +ONBOOT=no diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_AP_Mode.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_AP_Mode.cexpected new file mode 100644 index 00000000..ccec2b81 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_AP_Mode.cexpected @@ -0,0 +1,19 @@ +ESSID=MySSID +MODE=Ap +CHANNEL=196 +MAC_ADDRESS_RANDOMIZATION=default +AP_ISOLATION=yes +TYPE=Wireless +PROXY_METHOD=none +BROWSER_ONLY=no +BOOTPROTO=dhcp +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6INIT=yes +IPV6_AUTOCONF=yes +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no +IPV6_ADDR_GEN_MODE=stable-privacy +NAME="Test Write Wi-Fi AP Mode" +UUID=${UUID} +ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_Band_A.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_Band_A.cexpected new file mode 100644 index 00000000..ddbd986f --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_Band_A.cexpected @@ -0,0 +1,18 @@ +ESSID="Test SSID" +MODE=Managed +BAND=a +MAC_ADDRESS_RANDOMIZATION=default +TYPE=Wireless +PROXY_METHOD=none +BROWSER_ONLY=no +BOOTPROTO=dhcp +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6INIT=yes +IPV6_AUTOCONF=yes +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no +IPV6_ADDR_GEN_MODE=stable-privacy +NAME="Test Write Wi-Fi Band A" +UUID=${UUID} +ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_Hidden.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_Hidden.cexpected new file mode 100644 index 00000000..495a24d3 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_Hidden.cexpected @@ -0,0 +1,17 @@ +ESSID="Test SSID" +SSID_HIDDEN=yes +MAC_ADDRESS_RANDOMIZATION=default +TYPE=Wireless +PROXY_METHOD=none +BROWSER_ONLY=no +BOOTPROTO=dhcp +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6INIT=yes +IPV6_AUTOCONF=yes +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no +IPV6_ADDR_GEN_MODE=stable-privacy +NAME="Test Write Wi-Fi Hidden" +UUID=${UUID} +ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_MAC_always.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_MAC_always.cexpected new file mode 100644 index 00000000..aec6918a --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_MAC_always.cexpected @@ -0,0 +1,18 @@ +MACADDR=random +ESSID="Test SSID" +MODE=Managed +MAC_ADDRESS_RANDOMIZATION=always +TYPE=Wireless +PROXY_METHOD=none +BROWSER_ONLY=no +BOOTPROTO=dhcp +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6INIT=yes +IPV6_AUTOCONF=yes +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no +IPV6_ADDR_GEN_MODE=stable-privacy +NAME="Test Write Wi-Fi MAC always" +UUID=${UUID} +ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_MAC_default.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_MAC_default.cexpected new file mode 100644 index 00000000..9d47163f --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_MAC_default.cexpected @@ -0,0 +1,17 @@ +ESSID="Test SSID" +MODE=Managed +MAC_ADDRESS_RANDOMIZATION=default +TYPE=Wireless +PROXY_METHOD=none +BROWSER_ONLY=no +BOOTPROTO=dhcp +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6INIT=yes +IPV6_AUTOCONF=yes +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no +IPV6_ADDR_GEN_MODE=stable-privacy +NAME="Test Write Wi-Fi MAC default" +UUID=${UUID} +ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_MAC_missing.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_MAC_missing.cexpected new file mode 100644 index 00000000..43c07ddb --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_MAC_missing.cexpected @@ -0,0 +1,18 @@ +MACADDR=permanent +ESSID="Test SSID" +MODE=Managed +MAC_ADDRESS_RANDOMIZATION=never +TYPE=Wireless +PROXY_METHOD=none +BROWSER_ONLY=no +BOOTPROTO=dhcp +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6INIT=yes +IPV6_AUTOCONF=yes +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no +IPV6_ADDR_GEN_MODE=stable-privacy +NAME="Test Write Wi-Fi MAC missing" +UUID=${UUID} +ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_MAC_never.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_MAC_never.cexpected new file mode 100644 index 00000000..21f2e2de --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_WiFi_MAC_never.cexpected @@ -0,0 +1,18 @@ +MACADDR=permanent +ESSID="Test SSID" +MODE=Managed +MAC_ADDRESS_RANDOMIZATION=never +TYPE=Wireless +PROXY_METHOD=none +BROWSER_ONLY=no +BOOTPROTO=dhcp +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6INIT=yes +IPV6_AUTOCONF=yes +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no +IPV6_ADDR_GEN_MODE=stable-privacy +NAME="Test Write Wi-Fi MAC never" +UUID=${UUID} +ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wifi_LEAP.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wifi_LEAP.cexpected new file mode 100644 index 00000000..d3db19b2 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wifi_LEAP.cexpected @@ -0,0 +1,16 @@ +ESSID=blahblah +MODE=Managed +KEY_MGMT=IEEE8021X +SECURITYMODE=leap +IEEE_8021X_IDENTITY="Bill Smith" +MAC_ADDRESS_RANDOMIZATION=default +TYPE=Wireless +PROXY_METHOD=none +BROWSER_ONLY=no +BOOTPROTO=dhcp +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6INIT=no +NAME="Test Write Wifi LEAP" +UUID=${UUID} +ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wifi_WEP_104_ASCII.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wifi_WEP_104_ASCII.cexpected new file mode 100644 index 00000000..32db7262 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wifi_WEP_104_ASCII.cexpected @@ -0,0 +1,15 @@ +ESSID=blahblah104 +MODE=Managed +SECURITYMODE=open +DEFAULTKEY=1 +MAC_ADDRESS_RANDOMIZATION=default +TYPE=Wireless +PROXY_METHOD=none +BROWSER_ONLY=no +BOOTPROTO=dhcp +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6INIT=no +NAME="Test Write Wifi WEP 104 ASCII" +UUID=${UUID} +ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wired_Auto-Negotiate.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wired_Auto-Negotiate.cexpected new file mode 100644 index 00000000..214f5da5 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wired_Auto-Negotiate.cexpected @@ -0,0 +1,15 @@ +TYPE=Ethernet +PROXY_METHOD=none +BROWSER_ONLY=no +ETHTOOL_OPTS="autoneg off speed 10 duplex half" +BOOTPROTO=dhcp +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6INIT=yes +IPV6_AUTOCONF=yes +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no +IPV6_ADDR_GEN_MODE=stable-privacy +NAME="Test Write Wired Auto-Negotiate" +UUID=${UUID} +ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wired_Static_Routes.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wired_Static_Routes.cexpected new file mode 100644 index 00000000..cd8fc96f --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wired_Static_Routes.cexpected @@ -0,0 +1,22 @@ +HWADDR=31:33:33:37:BE:CD +MTU=1492 +TYPE=Ethernet +PROXY_METHOD=none +BROWSER_ONLY=no +BOOTPROTO=none +IPADDR=1.1.1.3 +PREFIX=24 +IPADDR1=1.1.1.5 +PREFIX1=24 +GATEWAY=1.1.1.1 +DNS1=4.2.2.1 +DNS2=4.2.2.2 +DOMAIN="foobar.com lab.foobar.com" +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +ACD_TIMEOUT=400 +ARPING_WAIT=1 +IPV6INIT=no +NAME="Test Write Wired Static Routes" +UUID=${UUID} +ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wired_Wake-on-LAN.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wired_Wake-on-LAN.cexpected new file mode 100644 index 00000000..de66dcdd --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wired_Wake-on-LAN.cexpected @@ -0,0 +1,15 @@ +TYPE=Ethernet +PROXY_METHOD=none +BROWSER_ONLY=no +ETHTOOL_OPTS="wol umgs sopass 00:00:00:11:22:33" +BOOTPROTO=dhcp +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6INIT=yes +IPV6_AUTOCONF=yes +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no +IPV6_ADDR_GEN_MODE=stable-privacy +NAME="Test Write Wired Wake-on-LAN" +UUID=${UUID} +ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wired_match.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wired_match.cexpected new file mode 100644 index 00000000..9499278e --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Test_Write_Wired_match.cexpected @@ -0,0 +1,13 @@ +TYPE=Ethernet +PROXY_METHOD=none +BROWSER_ONLY=no +MATCH_DRIVER="!virtio e1000e" +MATCH_INTERFACE_NAME="ens* eth\\ 1? !veth*" +MATCH_KERNEL_COMMAND_LINE=!ip= +BOOTPROTO=dhcp +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6INIT=no +NAME="Test Write Wired with Match setting" +UUID=${UUID} +ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Vlan_test-vlan-interface.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Vlan_test-vlan-interface.cexpected new file mode 100644 index 00000000..44eb777c --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-Vlan_test-vlan-interface.cexpected @@ -0,0 +1,23 @@ +VLAN=yes +TYPE=Vlan +PHYSDEV=eth9 +VLAN_ID=43 +REORDER_HDR=yes +GVRP=yes +VLAN_FLAGS=LOOSE_BINDING +MVRP=no +VLAN_INGRESS_PRIORITY_MAP=0:1,2:5 +VLAN_EGRESS_PRIORITY_MAP=3:1,12:3,14:7 +HWADDR= +PROXY_METHOD=none +BROWSER_ONLY=no +BOOTPROTO=none +IPADDR=192.168.43.149 +PREFIX=24 +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6INIT=no +NAME="Vlan test-vlan-interface" +UUID=${UUID} +DEVICE=vlan43 +ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-aliasem0 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-aliasem0 new file mode 100644 index 00000000..4f9d645c --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-aliasem0 @@ -0,0 +1,12 @@ +TYPE=Ethernet +DEVICE=aliasem0 +HWADDR=00:11:22:33:44:55 +BOOTPROTO=none +ONBOOT=yes +DNS1=4.2.2.1 +DNS2=4.2.2.2 +IPADDR=192.168.1.5 +PREFIX=24 +NETMASK=255.255.255.0 +GATEWAY=192.168.1.1 +IPV6INIT=no diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-aliasem0:1 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-aliasem0:1 new file mode 100644 index 00000000..37c0df11 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-aliasem0:1 @@ -0,0 +1,2 @@ +DEVICE=aliasem0:1 +IPADDR=192.168.1.6 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-aliasem0:2 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-aliasem0:2 new file mode 100644 index 00000000..0c3b6a7e --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-aliasem0:2 @@ -0,0 +1,2 @@ +DEVICE=aliasem0:2 +IPADDR=192.168.1.9 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-aliasem0:99 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-aliasem0:99 new file mode 100644 index 00000000..5df3f154 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-aliasem0:99 @@ -0,0 +1,2 @@ +DEVICE=aliasem0:99 +IPADDR=192.168.1.99 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-aliasem1 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-aliasem1 new file mode 100644 index 00000000..f6fefc0d --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-aliasem1 @@ -0,0 +1,12 @@ +TYPE=Ethernet +DEVICE=aliasem1 +HWADDR=00:11:22:33:44:55 +BOOTPROTO=none +ONBOOT=yes +DNS1=4.2.2.1 +DNS2=4.2.2.2 +IPADDR=192.168.1.5 +PREFIX=24 +NETMASK=255.255.255.0 +GATEWAY=192.168.1.1 +IPV6INIT=no diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-aliasem1:1 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-aliasem1:1 new file mode 100644 index 00000000..21971611 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-aliasem1:1 @@ -0,0 +1,2 @@ +# bad, no DEVICE +IPADDR=192.168.1.12 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-aliasem2 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-aliasem2 new file mode 100644 index 00000000..92ed461e --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-aliasem2 @@ -0,0 +1,12 @@ +TYPE=Ethernet +DEVICE=aliasem2 +HWADDR=00:11:22:33:44:55 +BOOTPROTO=none +ONBOOT=yes +DNS1=4.2.2.1 +DNS2=4.2.2.2 +IPADDR=192.168.1.5 +PREFIX=24 +NETMASK=255.255.255.0 +GATEWAY=192.168.1.1 +IPV6INIT=no diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-aliasem2:1 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-aliasem2:1 new file mode 100644 index 00000000..ce0f23ba --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-aliasem2:1 @@ -0,0 +1,3 @@ +# bad: wrong DEVICE +DEVICE=aliasem0:1 +IPADDR=192.168.1.20 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-aliasem3 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-aliasem3 new file mode 100644 index 00000000..b7bdd781 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-aliasem3 @@ -0,0 +1,11 @@ +TYPE=Ethernet +DEVICE=aliasem0 +HWADDR=00:11:22:33:44:55 +BOOTPROTO=none +ONBOOT=yes +DNS1=4.2.2.1 +DNS2=4.2.2.2 +IPADDR=192.168.1.5 +PREFIX=24 +NETMASK=255.255.255.0 +IPV6INIT=no diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-aliasem3:1 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-aliasem3:1 new file mode 100644 index 00000000..5e151875 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-aliasem3:1 @@ -0,0 +1,4 @@ +DEVICE=aliasem3:1 +IPADDR=192.168.1.6 +DEFROUTE=yes +GATEWAY=192.168.1.1 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-dcb-test.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-dcb-test.cexpected new file mode 100644 index 00000000..56e233cc --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-dcb-test.cexpected @@ -0,0 +1,41 @@ +TYPE=Ethernet +DCB=yes +DCB_APP_FCOE_ENABLE=yes +DCB_APP_FCOE_ADVERTISE=yes +DCB_APP_FCOE_WILLING=yes +DCB_APP_FCOE_PRIORITY=5 +DCB_APP_FCOE_MODE=fabric +DCB_APP_ISCSI_ENABLE=yes +DCB_APP_ISCSI_ADVERTISE=yes +DCB_APP_ISCSI_WILLING=yes +DCB_APP_ISCSI_PRIORITY=1 +DCB_APP_FIP_ENABLE=yes +DCB_APP_FIP_ADVERTISE=yes +DCB_APP_FIP_WILLING=yes +DCB_APP_FIP_PRIORITY=3 +DCB_PFC_ENABLE=yes +DCB_PFC_ADVERTISE=yes +DCB_PFC_WILLING=yes +DCB_PFC_UP=11010110 +DCB_PG_ENABLE=yes +DCB_PG_ADVERTISE=yes +DCB_PG_WILLING=yes +DCB_PG_ID=4f6f173f +DCB_PG_PCT=10,20,15,10,2,3,35,5 +DCB_PG_UPPCT=10,20,30,40,50,10,0,25 +DCB_PG_STRICT=10110001 +DCB_PG_UP2TC=34721056 +PROXY_METHOD=none +BROWSER_ONLY=no +BOOTPROTO=dhcp +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6INIT=yes +IPV6_AUTOCONF=yes +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no +IPV6_ADDR_GEN_MODE=stable-privacy +NAME=dcb-test +UUID=${UUID} +DEVICE=eth0 +ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-netmask-1 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-netmask-1 new file mode 100644 index 00000000..ecb36c37 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-netmask-1 @@ -0,0 +1,14 @@ +DNS1="192.0.2.1" +IPADDR="102.0.2.2" +GATEWAY="192.0.2.1" +NETMASK="255.254.0.0" +BOOTPROTO="static" +DEVICE="eth1" +ONBOOT="yes" +IPV6INIT="yes" + +#bogus +PREFIX1=25 +NETMASK0=255.255.0.0 + +#end diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-netmask-1.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-netmask-1.cexpected new file mode 100644 index 00000000..87493ac2 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-netmask-1.cexpected @@ -0,0 +1,22 @@ +DNS1=192.0.2.1 +IPADDR=102.0.2.2 +GATEWAY=192.0.2.1 +NETMASK=255.254.0.0 +DEVICE=eth1 +ONBOOT=yes +IPV6INIT=yes + +#bogus + +#end +TYPE=Ethernet +PROXY_METHOD=none +BROWSER_ONLY=no +PREFIX=15 +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6_AUTOCONF=yes +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no +NAME="System netmask-1" +UUID=${UUID} diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-random_wifi_connection.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-random_wifi_connection.cexpected new file mode 100644 index 00000000..ead3a047 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-random_wifi_connection.cexpected @@ -0,0 +1,13 @@ +ESSID=blahblah +MODE=Managed +MAC_ADDRESS_RANDOMIZATION=default +TYPE=Wireless +PROXY_METHOD=none +BROWSER_ONLY=no +BOOTPROTO=dhcp +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6INIT=no +NAME="random wifi connection" +UUID=${UUID} +ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-random_wifi_connection_2.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-random_wifi_connection_2.cexpected new file mode 100644 index 00000000..7bc1ae6c --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-random_wifi_connection_2.cexpected @@ -0,0 +1,15 @@ +ESSID=SomeSSID +MODE=Managed +MAC_ADDRESS_RANDOMIZATION=default +TYPE=Wireless +PROXY_METHOD=none +BROWSER_ONLY=no +BOOTPROTO=dhcp +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6INIT=no +NAME="random wifi connection 2" +UUID=${UUID} +ONBOOT=yes +USERS=superman +DEFAULTKEY=1 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-team-slave-enp31s0f1-142.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-team-slave-enp31s0f1-142.cexpected new file mode 100644 index 00000000..b01372af --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-team-slave-enp31s0f1-142.cexpected @@ -0,0 +1,13 @@ +VLAN=yes +PHYSDEV=enp31s0f1 +VLAN_ID=142 +REORDER_HDR=yes +GVRP=no +MVRP=no +HWADDR= +NAME=team-slave-enp31s0f1-142 +UUID=74f435bb-ede4-415a-9d48-f580b60eba04 +DEVICE=enp31s0f1-142 +ONBOOT=no +TEAM_MASTER=team142 +DEVICETYPE=TeamPort diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bond-eth-type b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bond-eth-type new file mode 100644 index 00000000..8d295c76 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bond-eth-type @@ -0,0 +1,7 @@ +DEVICE=bond0 +NM_CONTROLLED=yes +TYPE=Ethernet +BONDING_OPTS="miimon=213 mode=4 lacp_rate=1" +BONDING_MASTER=yes +ONBOOT=yes +BOOTPROTO=none diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bond-main b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bond-main new file mode 100644 index 00000000..4c4834d5 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bond-main @@ -0,0 +1,5 @@ +DEVICE=bond0 +ONBOOT=no +TYPE=Bond +BOOTPROTO=dhcp +BONDING_OPTS="miimon=100" diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bond-mode-numeric b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bond-mode-numeric new file mode 100644 index 00000000..9989f58b --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bond-mode-numeric @@ -0,0 +1,5 @@ +DEVICE=bond0 +ONBOOT=no +TYPE=Bond +BOOTPROTO=dhcp +BONDING_OPTS="mode=4 miimon=100" diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bond-slave b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bond-slave new file mode 100644 index 00000000..c0de645d --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bond-slave @@ -0,0 +1,6 @@ +DEVICE=eth0 +HWADDR=00:22:15:59:62:97 +ONBOOT=no +MASTER=bond0 +# This should be ignored +BOOTPROTO=dhcp diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bond-slave-ib b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bond-slave-ib new file mode 100644 index 00000000..5bd9a3a8 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bond-slave-ib @@ -0,0 +1,7 @@ +TYPE=InfiniBand +DEVICE=ib0 +HWADDR=80:00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22 +ONBOOT=no +MASTER=bond0 +# This should be ignored +BOOTPROTO=dhcp diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bridge-component b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bridge-component new file mode 100644 index 00000000..24b51221 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bridge-component @@ -0,0 +1,5 @@ +DEVICE=eth0 +HWADDR=00:22:15:59:62:97 +ONBOOT=no +BRIDGE=br0 +BRIDGING_OPTS="priority=28 hairpin_mode=1 path_cost=100" diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bridge-main b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bridge-main new file mode 100644 index 00000000..1788efe2 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bridge-main @@ -0,0 +1,8 @@ +DEVICE=br0 +ONBOOT=no +TYPE=Bridge +BOOTPROTO=dhcp +STP=on +DELAY=2 +BRIDGING_OPTS="priority=32744 hello_time=7 max_age=39 ageing_time=235352 multicast_snooping=0 group_fwd_mask=24 vlan_filtering=1 default_pvid=99" +MACADDR=00:16:41:11:22:33 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bridge-missing-stp b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bridge-missing-stp new file mode 100644 index 00000000..7135cd42 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-bridge-missing-stp @@ -0,0 +1,5 @@ +DEVICE=br0 +ONBOOT=no +TYPE=Bridge +BOOTPROTO=dhcp + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dcb b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dcb new file mode 100644 index 00000000..6e6589d3 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dcb @@ -0,0 +1,43 @@ +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=none +IPADDR=1.2.3.4 +PREFIX=24 +GATEWAY=1.1.1.1 + +# dcb global switch +# use DCB=no to turn it off +DCB=yes + +# application settings +DCB_APP_FCOE_PRIORITY=7 +DCB_APP_FCOE_ENABLE=yes +DCB_APP_FCOE_ADVERTISE=yes +DCB_APP_FCOE_WILLING=yes + +DCB_APP_ISCSI_PRIORITY=6 +DCB_APP_ISCSI_ENABLE=yes +DCB_APP_ISCSI_ADVERTISE=yes +DCB_APP_ISCSI_WILLING=yes + +DCB_APP_FIP_PRIORITY=2 +DCB_APP_FIP_ENABLE=yes +DCB_APP_FIP_ADVERTISE=yes +DCB_APP_FIP_WILLING=yes + +# priority group settings +DCB_PG_UP2TC=76543210 +DCB_PG_PCT=25,0,0,75,0,0,0,0 +DCB_PG_ID=0000111f +DCB_PG_UPPCT=5,10,30,25,10,50,5,0 +DCB_PG_STRICT=00110101 +DCB_PG_ENABLE=yes +DCB_PG_ADVERTISE=yes +DCB_PG_WILLING=yes + +# priority flow control settings +DCB_PFC_UP=10011010 +DCB_PFC_ENABLE=yes +DCB_PFC_ADVERTISE=yes +DCB_PFC_WILLING=no diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dcb-bad-booleans b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dcb-bad-booleans new file mode 100644 index 00000000..2f46a082 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dcb-bad-booleans @@ -0,0 +1,12 @@ +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=none +IPADDR=1.2.3.4 +PREFIX=24 +GATEWAY=1.1.1.1 + +DCB=yes +DCB_PG_STRICT=02030101 +DCB_PG_ENABLE=yes + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dcb-bad-percent b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dcb-bad-percent new file mode 100644 index 00000000..0c5d7b88 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dcb-bad-percent @@ -0,0 +1,12 @@ +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=none +IPADDR=1.2.3.4 +PREFIX=24 +GATEWAY=1.1.1.1 + +DCB=yes +DCB_PG_PCT=25,0,0,75,0,0,110,0 +DCB_PG_ENABLE=yes + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dcb-bad-uints b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dcb-bad-uints new file mode 100644 index 00000000..8334999b --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dcb-bad-uints @@ -0,0 +1,12 @@ +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=none +IPADDR=1.2.3.4 +PREFIX=24 +GATEWAY=1.1.1.1 + +DCB=yes +DCB_PG_UP2TC=96543210 +DCB_PG_ENABLE=yes + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dcb-default-app-priorities b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dcb-default-app-priorities new file mode 100644 index 00000000..5bdcb63c --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dcb-default-app-priorities @@ -0,0 +1,7 @@ +TYPE=Ethernet +DEVICE=eth0 +DCB=yes +DCB_APP_FCOE_ENABLE=yes +DCB_APP_ISCSI_ENABLE=yes +DCB_APP_FIP_ENABLE=yes + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dcb-pgpct-not-100 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dcb-pgpct-not-100 new file mode 100644 index 00000000..95eb7c5b --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dcb-pgpct-not-100 @@ -0,0 +1,12 @@ +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=none +IPADDR=1.2.3.4 +PREFIX=24 +GATEWAY=1.1.1.1 + +DCB=yes +DCB_PG_PCT=25,0,0,3,75,0,25,0 +DCB_PG_ENABLE=yes + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dcb-short-booleans b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dcb-short-booleans new file mode 100644 index 00000000..fbe1cbbc --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dcb-short-booleans @@ -0,0 +1,12 @@ +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=none +IPADDR=1.2.3.4 +PREFIX=24 +GATEWAY=1.1.1.1 + +DCB=yes +DCB_PG_STRICT=0111010 +DCB_PG_ENABLE=yes + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dcb-short-percent b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dcb-short-percent new file mode 100644 index 00000000..07ba6b64 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dcb-short-percent @@ -0,0 +1,12 @@ +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=none +IPADDR=1.2.3.4 +PREFIX=24 +GATEWAY=1.1.1.1 + +DCB=yes +DCB_PG_PCT=25,0,0,75,0,0,0 +DCB_PG_ENABLE=yes + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dcb-short-uints b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dcb-short-uints new file mode 100644 index 00000000..05ae39cb --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dcb-short-uints @@ -0,0 +1,12 @@ +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=none +IPADDR=1.2.3.4 +PREFIX=24 +GATEWAY=1.1.1.1 + +DCB=yes +DCB_PG_UP2TC=7654321 +DCB_PG_ENABLE=yes + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dns-options b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dns-options new file mode 100644 index 00000000..cea2471a --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-dns-options @@ -0,0 +1,16 @@ +TYPE=Ethernet +DEVICE=eth2 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=dhcp +ONBOOT=yes +USERCTL=yes +NM_CONTROLLED=yes +PEERDNS=yes +DNS1=10.2.0.4 +DOMAIN="lorem.com ipsum.org dolor.edu" +RES_OPTIONS="ndots:3 single-request-reopen" +IPV6_RES_OPTIONS="inet6" +IPV6INIT=yes +IPV6_AUTOCONF=no +IPV6ADDR="1001:abba::1234/56" +IPV6ADDR_SECONDARIES="2001:abba::2234/64 3001:abba::3234/96" diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-fcoe-fabric b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-fcoe-fabric new file mode 100644 index 00000000..cde1c28d --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-fcoe-fabric @@ -0,0 +1,6 @@ +TYPE=Ethernet +DEVICE=eth0 +DCB=yes +DCB_APP_FCOE_ENABLE=yes +DCB_APP_FCOE_MODE=fabric + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-fcoe-vn2vn b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-fcoe-vn2vn new file mode 100644 index 00000000..20c08451 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-fcoe-vn2vn @@ -0,0 +1,6 @@ +TYPE=Ethernet +DEVICE=eth0 +DCB=yes +DCB_APP_FCOE_ENABLE=yes +DCB_APP_FCOE_MODE=vn2vn + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-ibft b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-ibft new file mode 100644 index 00000000..d3e4edca --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-ibft @@ -0,0 +1,10 @@ +# Generated by dracut initrd +DEVICE="ibft0" +ONBOOT=yes +NETBOOT=yes +UUID="2aa8c19d-9744-4ca4-b74f-c37e73f2918e" +BOOTPROTO=ibft +HWADDR="00:33:21:98:b9:f0" +TYPE=Ethernet +NAME="ibft0" + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-infiniband b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-infiniband new file mode 100644 index 00000000..6c36f1de --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-infiniband @@ -0,0 +1,8 @@ +TYPE=InfiniBand +DEVICE=ib0 +HWADDR=80:00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22 +CONNECTED_MODE=yes +MTU=65520 +IPADDR=192.168.2.2 +NETMASK=255.255.255.0 +GATEWAY=192.168.2.1 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-ip6-disabled.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-ip6-disabled.cexpected new file mode 100644 index 00000000..cae51b89 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-ip6-disabled.cexpected @@ -0,0 +1,11 @@ +TYPE=Ethernet +PROXY_METHOD=none +BROWSER_ONLY=no +BOOTPROTO=dhcp +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6_DISABLED=yes +IPV6INIT=no +NAME="Test Write Wired Disabled IP6" +UUID=${UUID} +ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-minimal b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-minimal new file mode 100644 index 00000000..63bcc840 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-minimal @@ -0,0 +1,4 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +DEVICE=eth0 +HWADDR=00:16:41:11:22:33 + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-misc-variables b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-misc-variables new file mode 100644 index 00000000..1b10cddb --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-misc-variables @@ -0,0 +1,4 @@ +DEVICE=eth0 +HWADDR_BLACKLIST="00:16:41:11:22:88 00:16:41:11:22:99 XX:aa:invalid 6A:5D:5A:FA:DD:F0" +AUTOCONNECT_RETRIES=100 + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-nm-controlled b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-nm-controlled new file mode 100644 index 00000000..a38f1f5f --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-nm-controlled @@ -0,0 +1,9 @@ +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:f8:9f +BOOTPROTO=dhcp +ONBOOT=yes +USERCTL=yes +IPV6INIT=no +NM_CONTROLLED=no + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-nm-controlled-unrecognized b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-nm-controlled-unrecognized new file mode 100644 index 00000000..58263ece --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-nm-controlled-unrecognized @@ -0,0 +1,6 @@ +TYPE=IPoAC +NAME=PigeonNet +DEVICE=ipoac0 +BOOTPROTO=dhcp +ONBOOT=yes +NM_CONTROLLED=no diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-noip b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-noip new file mode 100644 index 00000000..b5028daa --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-noip @@ -0,0 +1,3 @@ +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=none diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-onboot-no b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-onboot-no new file mode 100644 index 00000000..b9491711 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-onboot-no @@ -0,0 +1,5 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +ONBOOT=no + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-permissions b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-permissions new file mode 100644 index 00000000..5b413aa9 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-permissions @@ -0,0 +1,8 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=dhcp +ONBOOT=yes +USERS="dcbw ssmith johnny5" + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-read-proxy-basic b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-read-proxy-basic new file mode 100644 index 00000000..e2cf6c21 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-read-proxy-basic @@ -0,0 +1,15 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=dhcp +ONBOOT=yes +USERCTL=yes +IPV6INIT=no +NM_CONTROLLED=yes +PEERDNS=no + +# proxy configuration +PROXY_METHOD=auto +PAC_URL=http://wpad.mycompany.com/wpad.dat +BROWSER_ONLY=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-sit-ignore b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-sit-ignore new file mode 100644 index 00000000..a2581db6 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-sit-ignore @@ -0,0 +1,12 @@ +# this ifcfg-file represents a "sit" type without explicit TYPE. +# Such connection types are not supported by NetworkManager and +# the connection should be ignored based on the presence of +# IPV6TUNNELIPV4. + +DEVICE=sit1 +BOOTPROTO=none +ONBOOT=yes +IPV6INIT=yes +IPV6TUNNELIPV4=5.4.3.6 +IPV6TUNNELIPV4LOCAL=172.17.1.9 +IPV6ADDR=2001:470:2:3:4::2/64 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-sriov b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-sriov new file mode 100644 index 00000000..142f56e4 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-sriov @@ -0,0 +1,19 @@ +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:55 +BOOTPROTO=none +ONBOOT=yes +DNS1=4.2.2.1 +DNS2=4.2.2.2 +IPADDR=192.168.1.5 +PREFIX=24 +NETMASK=255.255.255.0 +GATEWAY=192.168.1.1 +IPV6INIT=no +NAME=ethernet-sriov +UUID=acc703b8-e751-44ce-b456-1550bdf2057e +SRIOV_TOTAL_VFS=16 +SRIOV_AUTOPROBE_DRIVERS=0 +SRIOV_VF15="max-tx-rate=200 mac=01:23:45:67:89:ab vlans=2" +SRIOV_VF12="trust=false min-tx-rate=100 vlans=1.200.ad" +SRIOV_VF3="mac=55:44:33:22:11:00 spoof-check=true" diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-sriov-write.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-sriov-write.cexpected new file mode 100644 index 00000000..c882c479 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-sriov-write.cexpected @@ -0,0 +1,18 @@ +TYPE=Ethernet +PROXY_METHOD=none +BROWSER_ONLY=no +SRIOV_TOTAL_VFS=64 +SRIOV_AUTOPROBE_DRIVERS=1 +SRIOV_VF2="mac=55:55:55:55:55:55 vlans=3.10.ad;10" +SRIOV_VF19=spoof-check=true +BOOTPROTO=none +IPADDR=1.1.1.3 +PREFIX=24 +GATEWAY=1.1.1.1 +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6INIT=no +NAME="Test Write SR-IOV config" +UUID=${UUID} +DEVICE=eth0 +ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-static-routes-legacy b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-static-routes-legacy new file mode 100644 index 00000000..2173729d --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-static-routes-legacy @@ -0,0 +1,12 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +DEVICE=eth0 +HWADDR=00:16:41:11:22:33 +NAME="test-static-routes-legacy" +TYPE=Ethernet +BOOTPROTO=dhcp +DEFROUTE=yes +UUID=ba60d05a-7898-820d-c2db-427a88f8f2a5 +ONBOOT=yes +IPV6INIT=no +PEERDNS=yes +PEERROUTES=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-static-routes-legacy.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-static-routes-legacy.cexpected new file mode 100644 index 00000000..a28c5c1c --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-static-routes-legacy.cexpected @@ -0,0 +1,12 @@ +HWADDR=00:16:41:11:22:33 +TYPE=Ethernet +PROXY_METHOD=none +BROWSER_ONLY=no +BOOTPROTO=dhcp +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6INIT=no +NAME=test-static-routes-legacy +UUID=ba60d05a-7898-820d-c2db-427a88f8f2a5 +DEVICE=eth0 +ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-tc b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-tc new file mode 100644 index 00000000..d0a3c254 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-tc @@ -0,0 +1,16 @@ +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:55 +BOOTPROTO=none +ONBOOT=yes +DNS1=4.2.2.1 +DNS2=4.2.2.2 +IPADDR=192.168.1.5 +PREFIX=24 +NETMASK=255.255.255.0 +GATEWAY=192.168.1.1 +IPV6INIT=no +QDISC1="root fq_codel" +FILTER1="parent 1234: matchall action simple sdata Hello" +NAME=ethernet-tc +UUID=a42c8d4e-11a2-4144-92d2-5cbce8c6b2c4 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-tc-write.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-tc-write.cexpected new file mode 100644 index 00000000..a67ca598 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-tc-write.cexpected @@ -0,0 +1,16 @@ +TYPE=Ethernet +PROXY_METHOD=none +BROWSER_ONLY=no +QDISC1="parent 2468:2 pfifo_fast" +FILTER1="parent 1234: matchall action simple sdata Hello" +BOOTPROTO=none +IPADDR=1.1.1.3 +PREFIX=24 +GATEWAY=1.1.1.1 +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6INIT=no +NAME="Test Write TC config" +UUID=${UUID} +DEVICE=eth0 +ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-master-1 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-master-1 new file mode 100644 index 00000000..209447b8 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-master-1 @@ -0,0 +1,6 @@ +DEVICE=team0 +ONBOOT=no +DEVICETYPE=Team +BOOTPROTO=dhcp +TEAM_CONFIG="{\"device\": \"team0\", \"link_watch\": {\"name\": \"ethtool\"}}" + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-master-2 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-master-2 new file mode 100644 index 00000000..26e448cc --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-master-2 @@ -0,0 +1,5 @@ +DEVICE=team0 +ONBOOT=no +BOOTPROTO=dhcp +TEAM_CONFIG="{\"device\": \"team0\", \"link_watch\": {\"name\": \"ethtool\"}}" + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-master-invalid b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-master-invalid new file mode 100644 index 00000000..41c0f25c --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-master-invalid @@ -0,0 +1,4 @@ +DEVICE=team0 +ONBOOT=no +BOOTPROTO=dhcp +TEAM_CONFIG="{ foobar }x" diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-port-1 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-port-1 new file mode 100644 index 00000000..80355c26 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-port-1 @@ -0,0 +1,5 @@ +TYPE=Ethernet +TEAM_PORT_CONFIG="{\"p4p1\": {\"prio\": -10, \"sticky\": true}}" +DEVICE=p4p1 +TEAM_MASTER=team0 +DEVICETYPE=TeamPort diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-port-2 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-port-2 new file mode 100644 index 00000000..4284737a --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-port-2 @@ -0,0 +1,4 @@ +TYPE=Ethernet +TEAM_PORT_CONFIG="{\"p4p1\": {\"prio\": -10, \"sticky\": true}}" +DEVICE=p4p1 +TEAM_MASTER=team0 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-port-empty-config b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-port-empty-config new file mode 100644 index 00000000..04df6938 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-port-empty-config @@ -0,0 +1,4 @@ +TYPE=Ethernet +DEVICE=p4p1 +TEAM_MASTER=team0 +DEVICETYPE=TeamPort diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-unrecognized b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-unrecognized new file mode 100644 index 00000000..18da66c1 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-unrecognized @@ -0,0 +1,7 @@ +TYPE=PPP-over-InfiniBand +NAME=U Can't Touch This +DEVICE=pppoipoib0 +HWADDR=00:11:22:33 +BOOTPROTO=dhcp +ONBOOT=yes + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-variables-corner-cases-1 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-variables-corner-cases-1 new file mode 100644 index 00000000..af62dcfc --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-variables-corner-cases-1 @@ -0,0 +1,8 @@ +DEVICE=eth0 +HWADDR=00:16:41:11:22:33 + +# Variable with only single character (double quote) +NAME=" + +# Variable with only single character (quote) +ZONE=' diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-flags-1 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-flags-1 new file mode 100644 index 00000000..5ff87891 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-flags-1 @@ -0,0 +1,14 @@ +VLAN=yes +TYPE=Vlan +DEVICE=super-vlan +VLAN_ID=44 +PHYSDEV=eth9 +REORDER_HDR=yes +GVRP=no +VLAN_FLAGS="GVRP LOOSE_BINDING" +VLAN_INGRESS_PRIORITY_MAP=0:1,2:5 +VLAN_EGRESS_PRIORITY_MAP=12:3,14:7,3:1 +ONBOOT=yes +BOOTPROTO=static +IPADDR=192.168.43.149 +NETMASK=255.255.255.0 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-flags-2 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-flags-2 new file mode 100644 index 00000000..2c01be71 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-flags-2 @@ -0,0 +1,10 @@ +VLAN=yes +TYPE=Vlan +DEVICE=super-vlan +VLAN_ID=44 +PHYSDEV=eth9 +VLAN_FLAGS="GVRP LOOSE_BINDING" +ONBOOT=yes +BOOTPROTO=static +IPADDR=192.168.43.149 +NETMASK=255.255.255.0 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-interface b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-interface new file mode 100644 index 00000000..d8d9193f --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-interface @@ -0,0 +1,11 @@ +VLAN=yes +TYPE=Vlan +DEVICE=vlan43 +PHYSDEV=eth9 +VLAN_FLAGS=GVRP,LOOSE_BINDING +VLAN_INGRESS_PRIORITY_MAP=0:1,2:5 +VLAN_EGRESS_PRIORITY_MAP=12:3,14:7,3:1 +ONBOOT=yes +BOOTPROTO=static +IPADDR=192.168.43.149 +NETMASK=255.255.255.0 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-only-device b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-only-device new file mode 100644 index 00000000..4ba06f28 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-only-device @@ -0,0 +1,4 @@ +VLAN=yes +TYPE=Vlan +DEVICE=eth0.9 + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-only-vlanid b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-only-vlanid new file mode 100644 index 00000000..622d41ec --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-only-vlanid @@ -0,0 +1,6 @@ +VLAN=yes +TYPE=Vlan +PHYSDEV=eth9 +VLAN_ID=43 +ONBOOT=yes + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-physdev b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-physdev new file mode 100644 index 00000000..446c2a62 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-physdev @@ -0,0 +1,6 @@ +VLAN=yes +TYPE=Vlan +DEVICE=vlan0.3 +PHYSDEV=eth0 +VLAN_ID=3 + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-reorder-hdr-1 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-reorder-hdr-1 new file mode 100644 index 00000000..0dc53971 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-reorder-hdr-1 @@ -0,0 +1,6 @@ +VLAN=yes +TYPE=Vlan +DEVICE=vlan0.3 +PHYSDEV=eth0 +VLAN_ID=3 +REORDER_HDR=0 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-reorder-hdr-2 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-reorder-hdr-2 new file mode 100644 index 00000000..d98a9d36 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-reorder-hdr-2 @@ -0,0 +1,6 @@ +VLAN=yes +TYPE=Vlan +DEVICE=vlan0.3 +PHYSDEV=eth0 +VLAN_ID=3 +VLAN_FLAGS="LOOSE_BINDING,NO_REORDER_HDR" diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-trailing-spaces b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-trailing-spaces new file mode 100644 index 00000000..4a31e475 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-vlan-trailing-spaces @@ -0,0 +1,11 @@ +DEVICE="vlan201" +ONBOOT=yes +NETBOOT=yes +BOOTPROTO=none +IPADDR="10.130.70.7" +NETMASK="255.255.0.0" +TYPE=Vlan +NAME="vlan201" +VLAN=yes +PHYSDEV="enccw0.0.fb00" + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-band-a b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-band-a new file mode 100644 index 00000000..43286111 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-band-a @@ -0,0 +1,13 @@ +TYPE=Wireless +DEVICE=eth2 +HWADDR=00:16:41:11:22:33 +NM_CONTROLLED=yes +BOOTPROTO=dhcp +ESSID=blahblah +BAND=a +MODE=Managed +RATE=auto +ONBOOT=yes +USERCTL=yes +PEERDNS=yes +IPV6INIT=no diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-band-a-channel-mismatch b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-band-a-channel-mismatch new file mode 100644 index 00000000..8905ba0b --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-band-a-channel-mismatch @@ -0,0 +1,9 @@ +TYPE=Wireless +DEVICE=eth2 +HWADDR=00:16:41:11:22:33 +BOOTPROTO=dhcp +ESSID=blahblah +CHANNEL=9 +BAND=a +MODE=Managed + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-band-bg-channel-mismatch b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-band-bg-channel-mismatch new file mode 100644 index 00000000..e02e21ad --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-band-bg-channel-mismatch @@ -0,0 +1,9 @@ +TYPE=Wireless +DEVICE=eth2 +HWADDR=00:16:41:11:22:33 +BOOTPROTO=dhcp +ESSID=blahblah +CHANNEL=183 +BAND=bg +MODE=Managed + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-dynamic-wep-leap b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-dynamic-wep-leap new file mode 100644 index 00000000..d9c95cc2 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-dynamic-wep-leap @@ -0,0 +1,17 @@ +ESSID="sdasdsdg" +MODE=Managed +KEY_MGMT=IEEE8021X +CIPHER_GROUP="WEP40 WEP104" +TYPE=Wireless +IEEE_8021X_EAP_METHODS=LEAP +IEEE_8021X_IDENTITY="bill smith" +BOOTPROTO=dhcp +DEFROUTE=yes +PEERDNS=yes +PEERROUTES=yes +IPV4_FAILURE_FATAL=yes +IPV6INIT=no +NAME="Test Dynamic WEP LEAP" +UUID=aca7a23c-d934-49a3-8bfb-ad66f846c57b +ONBOOT=yes +USERS=dcbw diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-hidden b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-hidden new file mode 100644 index 00000000..08b9a730 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-hidden @@ -0,0 +1,10 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Wireless +DEVICE=eth2 +HWADDR=00:16:41:11:22:33 +BOOTPROTO=dhcp +ONBOOT=yes +ESSID=blahblah +MODE=Managed +SSID_HIDDEN=yes + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-leap b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-leap new file mode 100644 index 00000000..50f4fd31 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-leap @@ -0,0 +1,17 @@ +TYPE=Wireless +DEVICE=eth2 +HWADDR=00:16:41:11:22:33 +NM_CONTROLLED=yes +BOOTPROTO=dhcp +ESSID=blahblah +CHANNEL=1 +MODE=Managed +RATE=auto +ONBOOT=yes +USERCTL=yes +PEERDNS=yes +IPV6INIT=no +KEY_MGMT=IEEE8021X +SECURITYMODE=LEAP +IEEE_8021X_IDENTITY="Bill Smith" + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-leap-agent b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-leap-agent new file mode 100644 index 00000000..991ba67a --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-leap-agent @@ -0,0 +1,17 @@ +TYPE=Wireless +DEVICE=eth2 +HWADDR=00:16:41:11:22:33 +NM_CONTROLLED=yes +BOOTPROTO=dhcp +ESSID=blahblah +CHANNEL=1 +MODE=Managed +RATE=auto +ONBOOT=yes +USERCTL=yes +PEERDNS=yes +IPV6INIT=no +KEY_MGMT=IEEE8021X +SECURITYMODE=LEAP +IEEE_8021X_IDENTITY="Bill Smith" +IEEE_8021X_PASSWORD_FLAGS=user diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-leap-always-ask b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-leap-always-ask new file mode 100644 index 00000000..5bb02b5c --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-leap-always-ask @@ -0,0 +1,17 @@ +TYPE=Wireless +DEVICE=eth2 +HWADDR=00:16:41:11:22:33 +NM_CONTROLLED=yes +BOOTPROTO=dhcp +ESSID=blahblah +CHANNEL=1 +MODE=Managed +RATE=auto +ONBOOT=yes +USERCTL=yes +PEERDNS=yes +IPV6INIT=no +KEY_MGMT=IEEE8021X +SECURITYMODE=LEAP +IEEE_8021X_IDENTITY="Bill Smith" +IEEE_8021X_PASSWORD_FLAGS="user ask" diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-mac-random-always b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-mac-random-always new file mode 100644 index 00000000..9dcb5bf8 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-mac-random-always @@ -0,0 +1,7 @@ +TYPE=Wireless +DEVICE=eth2 +BOOTPROTO=dhcp +ESSID=blahblah +ONBOOT=yes +MAC_ADDRESS_RANDOMIZATION=always + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-mac-random-default b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-mac-random-default new file mode 100644 index 00000000..3709c493 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-mac-random-default @@ -0,0 +1,6 @@ +TYPE=Wireless +DEVICE=eth2 +BOOTPROTO=dhcp +ESSID=blahblah +ONBOOT=yes +MAC_ADDRESS_RANDOMIZATION=default diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-mac-random-missing b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-mac-random-missing new file mode 100644 index 00000000..f896eb0f --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-mac-random-missing @@ -0,0 +1,6 @@ +TYPE=Wireless +DEVICE=eth2 +BOOTPROTO=dhcp +ESSID=blahblah +ONBOOT=yes + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-mac-random-never b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-mac-random-never new file mode 100644 index 00000000..aa12d749 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-mac-random-never @@ -0,0 +1,6 @@ +TYPE=Wireless +DEVICE=eth2 +BOOTPROTO=dhcp +ESSID=blahblah +ONBOOT=yes +MAC_ADDRESS_RANDOMIZATION=never diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-open b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-open new file mode 100644 index 00000000..b089103d --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-open @@ -0,0 +1,16 @@ +TYPE=Wireless +DEVICE=eth2 +HWADDR=00:16:41:11:22:33 +NM_CONTROLLED=yes +BOOTPROTO=dhcp +AUTOCONNECT_PRIORITY=-1 +ESSID=blahblah +CHANNEL=1 +MODE=Managed +RATE=auto +ONBOOT=yes +USERCTL=yes +PEERDNS=yes +IPV6INIT=no +IPV4_ROUTE_METRIC=104 +IPV6_ROUTE_METRIC=106 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-open-auto b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-open-auto new file mode 100644 index 00000000..42ee200a --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-open-auto @@ -0,0 +1,13 @@ +TYPE=Wireless +DEVICE=eth2 +HWADDR=00:16:41:11:22:33 +NM_CONTROLLED=yes +BOOTPROTO=dhcp +ESSID=blahblah +CHANNEL=1 +MODE=Auto +RATE=auto +ONBOOT=yes +USERCTL=yes +PEERDNS=yes +IPV6INIT=no diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-open-ssid-bad-hex b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-open-ssid-bad-hex new file mode 100644 index 00000000..32d63342 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-open-ssid-bad-hex @@ -0,0 +1,13 @@ +TYPE=Wireless +DEVICE=eth2 +HWADDR=00:16:41:11:22:33 +NM_CONTROLLED=yes +BOOTPROTO=dhcp +ESSID=0x626cxx +CHANNEL=1 +MODE=Managed +RATE=auto +ONBOOT=yes +USERCTL=yes +PEERDNS=yes +IPV6INIT=no diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-open-ssid-hex b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-open-ssid-hex new file mode 100644 index 00000000..dcb46da7 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-open-ssid-hex @@ -0,0 +1,13 @@ +TYPE=Wireless +DEVICE=eth2 +HWADDR=00:16:41:11:22:33 +NM_CONTROLLED=yes +BOOTPROTO=dhcp +ESSID=0x626c6168626c6168 +CHANNEL=1 +MODE=Managed +RATE=auto +ONBOOT=yes +USERCTL=yes +PEERDNS=yes +IPV6INIT=no diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-open-ssid-long-hex b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-open-ssid-long-hex new file mode 100644 index 00000000..37bb085b --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-open-ssid-long-hex @@ -0,0 +1,13 @@ +TYPE=Wireless +DEVICE=eth2 +HWADDR=00:16:41:11:22:33 +NM_CONTROLLED=yes +BOOTPROTO=dhcp +ESSID=0x626c6168626c6168626c6168626c6168626c6168626c6168626c6168626c6168AA +CHANNEL=1 +MODE=Managed +RATE=auto +ONBOOT=yes +USERCTL=yes +PEERDNS=yes +IPV6INIT=no diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-open-ssid-long-quoted b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-open-ssid-long-quoted new file mode 100644 index 00000000..0b46acd6 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-open-ssid-long-quoted @@ -0,0 +1,13 @@ +TYPE=Wireless +DEVICE=eth2 +HWADDR=00:16:41:11:22:33 +NM_CONTROLLED=yes +BOOTPROTO=dhcp +ESSID="foo\"bar\\foo\"bar\\foo\"bar\\foo\"bar\\1" +CHANNEL=1 +MODE=Managed +RATE=auto +ONBOOT=yes +USERCTL=yes +PEERDNS=yes +IPV6INIT=no diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-open-ssid-quoted b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-open-ssid-quoted new file mode 100644 index 00000000..08496bb5 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-open-ssid-quoted @@ -0,0 +1,13 @@ +TYPE=Wireless +DEVICE=eth2 +HWADDR=00:16:41:11:22:33 +NM_CONTROLLED=yes +BOOTPROTO=dhcp +ESSID="foo\"bar\\" +CHANNEL=1 +MODE=Managed +RATE=auto +ONBOOT=yes +USERCTL=yes +PEERDNS=yes +IPV6INIT=no diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-owe b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-owe new file mode 100644 index 00000000..354046ad --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-owe @@ -0,0 +1,5 @@ +TYPE=Wireless +DEVICE=wlan1 +ESSID=blahblah_owe +MODE=Managed +KEY_MGMT=OWE diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-sae b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-sae new file mode 100644 index 00000000..68afbe97 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-sae @@ -0,0 +1,5 @@ +TYPE=Wireless +DEVICE=wlan1 +ESSID=blahblah +MODE=Managed +KEY_MGMT=SAE diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wep b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wep new file mode 100644 index 00000000..e1ce20d6 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wep @@ -0,0 +1,14 @@ +TYPE=Wireless +DEVICE=eth2 +HWADDR=00:16:41:11:22:33 +NM_CONTROLLED=yes +BOOTPROTO=dhcp +ESSID=blahblah +CHANNEL=1 +MODE=Managed +RATE=auto +ONBOOT=yes +USERCTL=yes +PEERDNS=yes +IPV6INIT=no +SECURITYMODE=restricted diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wep-104-ascii b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wep-104-ascii new file mode 100644 index 00000000..250efa13 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wep-104-ascii @@ -0,0 +1,14 @@ +TYPE=Wireless +DEVICE=eth2 +HWADDR=00:16:41:11:22:33 +NM_CONTROLLED=yes +BOOTPROTO=dhcp +ESSID=blahblah +CHANNEL=1 +MODE=Managed +RATE=auto +ONBOOT=yes +USERCTL=yes +PEERDNS=yes +IPV6INIT=no +SECURITYMODE=open diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wep-40-ascii b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wep-40-ascii new file mode 100644 index 00000000..250efa13 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wep-40-ascii @@ -0,0 +1,14 @@ +TYPE=Wireless +DEVICE=eth2 +HWADDR=00:16:41:11:22:33 +NM_CONTROLLED=yes +BOOTPROTO=dhcp +ESSID=blahblah +CHANNEL=1 +MODE=Managed +RATE=auto +ONBOOT=yes +USERCTL=yes +PEERDNS=yes +IPV6INIT=no +SECURITYMODE=open diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wep-adhoc b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wep-adhoc new file mode 100644 index 00000000..9d0bacfc --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wep-adhoc @@ -0,0 +1,15 @@ +TYPE=Wireless +DEVICE=eth2 +HWADDR=00:16:41:11:22:33 +NM_CONTROLLED=yes +BOOTPROTO=dhcp +ESSID=blahblah +CHANNEL=11 +MODE=Ad-Hoc +RATE=auto +ONBOOT=no +USERCTL=yes +PEERDNS=no +DNS1=4.2.2.1 +DNS2=4.2.2.2 +IPV6INIT=no diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wep-agent-keys b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wep-agent-keys new file mode 100644 index 00000000..2bc16b6e --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wep-agent-keys @@ -0,0 +1,18 @@ +ESSID="foobar" +MODE=Managed +TYPE=Wireless +BOOTPROTO=dhcp +DEFROUTE=yes +IPV4_FAILURE_FATAL=yes +IPV6INIT=yes +IPV6_AUTOCONF=yes +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no +UUID=9c4637bd-7600-40cc-9c24-13819c5bf5dd +ONBOOT=yes +HWADDR=00:16:BB:AA:CC:DD +WEP_KEY_FLAGS=user +PEERDNS=yes +PEERROUTES=yes +IPV6_PEERDNS=yes +IPV6_PEERROUTES=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wep-eap-ttls-chap b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wep-eap-ttls-chap new file mode 100644 index 00000000..bdea6aa3 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wep-eap-ttls-chap @@ -0,0 +1,20 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Wireless +DEVICE=eth2 +HWADDR=00:16:41:11:22:33 +BOOTPROTO=dhcp +ONBOOT=yes +ONBOOT=yes +USERCTL=yes +IPV6INIT=no +NM_CONTROLLED=yes +PEERDNS=yes +ESSID=blahblah +MODE=Managed +RATE=auto +KEY_MGMT=IEEE8021X +IEEE_8021X_EAP_METHODS=TTLS +IEEE_8021X_IDENTITY="David Smith" +IEEE_8021X_CA_CERT=test_ca_cert.pem +IEEE_8021X_INNER_AUTH_METHODS=CHAP + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wep-no-keys b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wep-no-keys new file mode 100644 index 00000000..cb4da43f --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wep-no-keys @@ -0,0 +1,18 @@ +ESSID="foobar" +MODE=Managed +TYPE=Wireless +BOOTPROTO=dhcp +DEFROUTE=yes +IPV4_FAILURE_FATAL=yes +IPV6INIT=yes +IPV6_AUTOCONF=yes +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no +UUID=9c4637bd-7600-40cc-9c24-13819c5bf5dd +ONBOOT=yes +HWADDR=00:16:BB:AA:CC:DD +DEFAULTKEY=1 +PEERDNS=yes +PEERROUTES=yes +IPV6_PEERDNS=yes +IPV6_PEERROUTES=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wep-passphrase b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wep-passphrase new file mode 100644 index 00000000..250efa13 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wep-passphrase @@ -0,0 +1,14 @@ +TYPE=Wireless +DEVICE=eth2 +HWADDR=00:16:41:11:22:33 +NM_CONTROLLED=yes +BOOTPROTO=dhcp +ESSID=blahblah +CHANNEL=1 +MODE=Managed +RATE=auto +ONBOOT=yes +USERCTL=yes +PEERDNS=yes +IPV6INIT=no +SECURITYMODE=open diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-eap-suite-b-192-tls b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-eap-suite-b-192-tls new file mode 100644 index 00000000..9a74bb4d --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-eap-suite-b-192-tls @@ -0,0 +1,22 @@ +TYPE=Wireless +DEVICE=eth2 +HWADDR=00:16:41:11:22:33 +BOOTPROTO=dhcp +ONBOOT=yes +ONBOOT=yes +USERCTL=yes +IPV6INIT=no +NM_CONTROLLED=yes +PEERDNS=yes +ESSID=blahblah +MODE=Managed +RATE=auto +KEY_MGMT=WPA-EAP-SUITE-B-192 +WPA_ALLOW_WPA=yes +WPA_ALLOW_WPA2=yes +IEEE_8021X_EAP_METHODS=TLS +IEEE_8021X_IDENTITY="Bill Smith" +IEEE_8021X_CA_CERT=test_ca_cert.pem +IEEE_8021X_CLIENT_CERT=test1_key_and_cert.pem +IEEE_8021X_PRIVATE_KEY=test1_key_and_cert.pem + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-eap-tls b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-eap-tls new file mode 100644 index 00000000..92aaeeab --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-eap-tls @@ -0,0 +1,25 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Wireless +DEVICE=eth2 +HWADDR=00:16:41:11:22:33 +BOOTPROTO=dhcp +ONBOOT=yes +ONBOOT=yes +USERCTL=yes +IPV6INIT=no +NM_CONTROLLED=yes +PEERDNS=yes +ESSID=blahblah +MODE=Managed +RATE=auto +CIPHER_PAIRWISE="TKIP CCMP" +CIPHER_GROUP="TKIP CCMP WEP40 WEP104" +KEY_MGMT=WPA-EAP +WPA_ALLOW_WPA=yes +WPA_ALLOW_WPA2=yes +IEEE_8021X_EAP_METHODS=TLS +IEEE_8021X_IDENTITY="Bill Smith" +IEEE_8021X_CA_CERT=test_ca_cert.pem +IEEE_8021X_CLIENT_CERT=test1_key_and_cert.pem +IEEE_8021X_PRIVATE_KEY=test1_key_and_cert.pem + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-eap-ttls-tls b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-eap-ttls-tls new file mode 100644 index 00000000..42ed1d68 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-eap-ttls-tls @@ -0,0 +1,28 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Wireless +DEVICE=eth2 +HWADDR=00:16:41:11:22:33 +BOOTPROTO=dhcp +ONBOOT=yes +ONBOOT=yes +USERCTL=yes +IPV6INIT=no +NM_CONTROLLED=yes +PEERDNS=yes +ESSID=blahblah +MODE=Managed +RATE=auto +CIPHER_PAIRWISE="TKIP CCMP" +CIPHER_GROUP="TKIP CCMP WEP40 WEP104" +KEY_MGMT=WPA-EAP +WPA_ALLOW_WPA=yes +WPA_ALLOW_WPA2=yes +IEEE_8021X_EAP_METHODS=TTLS +IEEE_8021X_IDENTITY="Chuck Shumer" +IEEE_8021X_ANON_IDENTITY="anonymous" +IEEE_8021X_CA_CERT=test_ca_cert.pem +IEEE_8021X_INNER_AUTH_METHODS=EAP-TLS +IEEE_8021X_INNER_CA_CERT=test_ca_cert.pem +IEEE_8021X_INNER_CLIENT_CERT=test1_key_and_cert.pem +IEEE_8021X_INNER_PRIVATE_KEY=test1_key_and_cert.pem + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-psk b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-psk new file mode 100644 index 00000000..4ab45ae3 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-psk @@ -0,0 +1,19 @@ +TYPE=Wireless +DEVICE=eth2 +HWADDR=00:16:41:11:22:33 +NM_CONTROLLED=yes +BOOTPROTO=dhcp +ESSID=blahblah +CHANNEL=1 +MODE=Managed +RATE=auto +ONBOOT=yes +USERCTL=yes +PEERDNS=yes +IPV6INIT=no +CIPHER_PAIRWISE="TKIP CCMP" +CIPHER_GROUP="TKIP CCMP WEP40 WEP104" +KEY_MGMT=WPA-PSK +WPA_ALLOW_WPA=yes +WPA_ALLOW_WPA2=yes +CTCPROT=no-newline \ No newline at end of file diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-psk-2 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-psk-2 new file mode 100644 index 00000000..038b656d --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-psk-2 @@ -0,0 +1,19 @@ +TYPE=Wireless +DEVICE=eth2 +HWADDR=00:16:41:11:22:33 +NM_CONTROLLED=yes +BOOTPROTO=dhcp +ESSID=ipsum +CHANNEL=6 +MODE=Managed +RATE=auto +ONBOOT=yes +USERCTL=yes +PEERDNS=yes +IPV6INIT=no +CIPHER_PAIRWISE="TKIP CCMP" +CIPHER_GROUP="TKIP CCMP WEP40 WEP104" +KEY_MGMT=WPA-PSK +WPA_ALLOW_WPA=yes +WPA_ALLOW_WPA2=yes + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-psk-adhoc b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-psk-adhoc new file mode 100644 index 00000000..c3cadbb8 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-psk-adhoc @@ -0,0 +1,17 @@ +TYPE=Wireless +DEVICE=eth2 +HWADDR=00:16:41:11:22:33 +NM_CONTROLLED=yes +BOOTPROTO=dhcp +ESSID=blahblah +CHANNEL=1 +MODE=Ad-Hoc +RATE=auto +ONBOOT=yes +USERCTL=yes +PEERDNS=yes +IPV6INIT=no +CIPHER_GROUP=CCMP +CIPHER_PAIRWISE=CCMP +KEY_MGMT=WPA-PSK + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-psk-hex b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-psk-hex new file mode 100644 index 00000000..2119ba8e --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-psk-hex @@ -0,0 +1,19 @@ +TYPE=Wireless +DEVICE=eth2 +HWADDR=00:16:41:11:22:33 +NM_CONTROLLED=yes +BOOTPROTO=dhcp +ESSID=blahblah +CHANNEL=1 +MODE=Managed +RATE=auto +ONBOOT=yes +USERCTL=yes +PEERDNS=yes +IPV6INIT=no +CIPHER_PAIRWISE="TKIP CCMP" +CIPHER_GROUP="TKIP CCMP WEP40 WEP104" +KEY_MGMT=WPA-PSK +WPA_ALLOW_WPA=yes +WPA_ALLOW_WPA2=yes + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-psk-unquoted b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-psk-unquoted new file mode 100644 index 00000000..2119ba8e --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-psk-unquoted @@ -0,0 +1,19 @@ +TYPE=Wireless +DEVICE=eth2 +HWADDR=00:16:41:11:22:33 +NM_CONTROLLED=yes +BOOTPROTO=dhcp +ESSID=blahblah +CHANNEL=1 +MODE=Managed +RATE=auto +ONBOOT=yes +USERCTL=yes +PEERDNS=yes +IPV6INIT=no +CIPHER_PAIRWISE="TKIP CCMP" +CIPHER_GROUP="TKIP CCMP WEP40 WEP104" +KEY_MGMT=WPA-PSK +WPA_ALLOW_WPA=yes +WPA_ALLOW_WPA2=yes + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-psk-unquoted2 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-psk-unquoted2 new file mode 100644 index 00000000..2119ba8e --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wifi-wpa-psk-unquoted2 @@ -0,0 +1,19 @@ +TYPE=Wireless +DEVICE=eth2 +HWADDR=00:16:41:11:22:33 +NM_CONTROLLED=yes +BOOTPROTO=dhcp +ESSID=blahblah +CHANNEL=1 +MODE=Managed +RATE=auto +ONBOOT=yes +USERCTL=yes +PEERDNS=yes +IPV6INIT=no +CIPHER_PAIRWISE="TKIP CCMP" +CIPHER_GROUP="TKIP CCMP WEP40 WEP104" +KEY_MGMT=WPA-PSK +WPA_ALLOW_WPA=yes +WPA_ALLOW_WPA2=yes + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-802-1X-subj-matches b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-802-1X-subj-matches new file mode 100644 index 00000000..70d69bf5 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-802-1X-subj-matches @@ -0,0 +1,17 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=dhcp +ONBOOT=yes +NM_CONTROLLED=yes +KEY_MGMT=IEEE8021X +IEEE_8021X_EAP_METHODS=PEAP +IEEE_8021X_IDENTITY="Jara Cimrman" +IEEE_8021X_PEAP_VERSION=1 +IEEE_8021X_INNER_AUTH_METHODS=GTC +IEEE_8021X_PASSWORD_FLAGS="user ask" +IEEE_8021X_SUBJECT_MATCH=server1.yourdomain.tld +IEEE_8021X_ALTSUBJECT_MATCHES="a.yourdomain.tld b.yourdomain.tld c.yourdomain.tld" +IEEE_8021X_PHASE2_SUBJECT_MATCH=server2.yourdomain.tld +IEEE_8021X_PHASE2_ALTSUBJECT_MATCHES="x.yourdomain.tld y.yourdomain.tld" diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-802-1x-password-raw b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-802-1x-password-raw new file mode 100644 index 00000000..a5434434 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-802-1x-password-raw @@ -0,0 +1,15 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=dhcp +ONBOOT=yes +NM_CONTROLLED=yes +KEY_MGMT=IEEE8021X +IEEE_8021X_EAP_METHODS=TTLS +IEEE_8021X_IDENTITY="Bill Smith" +IEEE_8021X_CA_CERT=test_ca_cert.pem +IEEE_8021X_INNER_AUTH_METHODS=EAP-GTC +IEEE_8021X_PASSWORD_RAW=0408151623420001 +#IEEE_8021X_PIN=hallo1 +IEEE_8021X_PIN_FLAGS=0 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-802-1x-ttls-eapgtc b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-802-1x-ttls-eapgtc new file mode 100644 index 00000000..fad92772 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-802-1x-ttls-eapgtc @@ -0,0 +1,13 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=dhcp +ONBOOT=yes +NM_CONTROLLED=yes +KEY_MGMT=IEEE8021X +IEEE_8021X_EAP_METHODS=TTLS +IEEE_8021X_IDENTITY="Bill Smith" +IEEE_8021X_CA_CERT=test_ca_cert.pem +IEEE_8021X_INNER_AUTH_METHODS=EAP-GTC +IEEE_8021X_PASSWORD_FLAGS=ask diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-8021x-peap-mschapv2 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-8021x-peap-mschapv2 new file mode 100644 index 00000000..27bcbbf9 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-8021x-peap-mschapv2 @@ -0,0 +1,15 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=dhcp +ONBOOT=yes +NM_CONTROLLED=yes +KEY_MGMT=IEEE8021X +IEEE_8021X_EAP_METHODS=PEAP +IEEE_8021X_IDENTITY="David Smith" +IEEE_8021X_CA_CERT=test_ca_cert.pem +IEEE_8021X_PEAP_VERSION=1 +IEEE_8021X_PEAP_FORCE_NEW_LABEL=yes +IEEE_8021X_INNER_AUTH_METHODS=MSCHAPV2 +IEEE_8021X_ANON_IDENTITY=somebody diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-8021x-tls-agent b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-8021x-tls-agent new file mode 100644 index 00000000..052ab425 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-8021x-tls-agent @@ -0,0 +1,14 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=dhcp +ONBOOT=yes +NM_CONTROLLED=yes +KEY_MGMT=IEEE8021X +IEEE_8021X_EAP_METHODS=TLS +IEEE_8021X_IDENTITY="David Smith" +IEEE_8021X_CA_CERT=test_ca_cert.pem +IEEE_8021X_CLIENT_CERT=test1_key_and_cert.pem +IEEE_8021X_PRIVATE_KEY=test1_key_and_cert.pem +IEEE_8021X_PRIVATE_KEY_PASSWORD_FLAGS=user diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-8021x-tls-always b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-8021x-tls-always new file mode 100644 index 00000000..5deee066 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-8021x-tls-always @@ -0,0 +1,14 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=dhcp +ONBOOT=yes +NM_CONTROLLED=yes +KEY_MGMT=IEEE8021X +IEEE_8021X_EAP_METHODS=TLS +IEEE_8021X_IDENTITY="David Smith" +IEEE_8021X_CA_CERT=test_ca_cert.pem +IEEE_8021X_CLIENT_CERT=test1_key_and_cert.pem +IEEE_8021X_PRIVATE_KEY=test1_key_and_cert.pem +IEEE_8021X_PRIVATE_KEY_PASSWORD_FLAGS="user ask" diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-8021x-tls-p12-no-client-cert b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-8021x-tls-p12-no-client-cert new file mode 100644 index 00000000..24397473 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-8021x-tls-p12-no-client-cert @@ -0,0 +1,13 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=dhcp +ONBOOT=yes +NM_CONTROLLED=yes +KEY_MGMT=IEEE8021X +IEEE_8021X_EAP_METHODS=TLS +IEEE_8021X_IDENTITY="David Smith" +IEEE_8021X_CA_CERT=test_ca_cert.pem +IEEE_8021X_PRIVATE_KEY=test_client.p12 +IEEE_8021X_PRIVATE_KEY_PASSWORD="test1" diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-auto-negotiate-on b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-auto-negotiate-on new file mode 100644 index 00000000..d0b50775 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-auto-negotiate-on @@ -0,0 +1,22 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=none +ONBOOT=yes +USERCTL=yes +MTU=1492 +NM_CONTROLLED=yes +DNS1=4.2.2.1 +DNS2=4.2.2.2 +IPADDR=192.168.1.5 +NETMASK=255.255.255.0 +GATEWAY=192.168.1.1 +IPV6INIT=yes +IPV6_AUTOCONF=no +IPV6ADDR=dead:beaf::1 +IPV6ADDR_SECONDARIES="dead:beaf::2/56" +DNS3=1:2:3:4::a +DNS4=1:2:3:4::b +RES_OPTIONS= +ETHTOOL_OPTS="wol apgs sopass 00:11:22:33:44:55 autoneg on speed 100" diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-autoip b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-autoip new file mode 100644 index 00000000..e683db3c --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-autoip @@ -0,0 +1,6 @@ +TYPE=Ethernet +DEVICE=eth0 +BOOTPROTO=autoip +IPV4_FAILURE_FATAL=yes +PEERDNS=no +DEVTIMEOUT=2.6 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-ctc-static b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-ctc-static new file mode 100644 index 00000000..61f8f423 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-ctc-static @@ -0,0 +1,12 @@ +# IBM CTC +DEVICE=ctc0 +TYPE=CTC +BOOTPROTO=static +IPADDR=192.168.70.87 +GATEWAY=192.168.70.136 +NETMASK=255.255.255.0 +ONBOOT=yes +SUBCHANNELS=0.0.1b00,0.0.1b01 +NETTYPE=ctc +CTCPROT=0 + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-defroute-no b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-defroute-no new file mode 100644 index 00000000..fe8b15b2 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-defroute-no @@ -0,0 +1,15 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth4 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=dhcp +ONBOOT=yes +USERCTL=yes +NM_CONTROLLED=yes +PEERDNS=yes +DEFROUTE=no + +IPV6INIT=yes +IPV6_AUTOCONF=yes +IPV6_DEFROUTE=no + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-defroute-no-gatewaydev-yes b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-defroute-no-gatewaydev-yes new file mode 100644 index 00000000..3cf4323d --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-defroute-no-gatewaydev-yes @@ -0,0 +1,15 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=dhcp +ONBOOT=yes +USERCTL=yes +NM_CONTROLLED=yes +PEERDNS=yes +DEFROUTE=no + +IPV6INIT=yes +IPV6_AUTOCONF=yes +IPV6_DEFROUTE=no + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-dhcp b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-dhcp new file mode 100644 index 00000000..5d36675a --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-dhcp @@ -0,0 +1,19 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=dhcp +ONBOOT=yes +USERCTL=yes +IPV6INIT=no +NM_CONTROLLED=yes +PEERDNS=no +DHCP_FQDN=foo.bar +DHCP_HOSTNAME_FLAGS=6 +DNS1=4.2.2.1 +DNS2=4.2.2.2 +IPV6_AUTOCONF=no +IPV6INIT=yes +DHCPV6C=yes +DHCPV6_HOSTNAME_FLAGS=8 +DHCPV6_HOSTNAME=foo.bar diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-dhcp-plus-ip b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-dhcp-plus-ip new file mode 100644 index 00000000..af254f9c --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-dhcp-plus-ip @@ -0,0 +1,26 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=dhcp +ONBOOT=yes +IPV6INIT=yes +IPV6_AUTOCONF=yes +USERCTL=yes +NM_CONTROLLED=yes +PEERDNS=no +DNS1=4.2.2.1 +DNS2=4.2.2.2 +DNS3=1:2:3:4::a +DNS4=1:2:3:4::b + +# additional IPs +IPADDR=1.2.3.4 +PREFIX=24 +IPADDR1=9.8.7.6 +PREFIX1=16 +GATEWAY=1.1.1.1 + +IPV6ADDR="1001:abba::1234/56" +IPV6ADDR_SECONDARIES="2001:abba::2234/64 3001:abba::3234/96" + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-dhcp-send-hostname b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-dhcp-send-hostname new file mode 100644 index 00000000..cba380db --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-dhcp-send-hostname @@ -0,0 +1,12 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=dhcp +ONBOOT=yes +IPV6INIT=yes +IPV6_AUTOCONF=yes +USERCTL=yes +NM_CONTROLLED=yes +PEERDNS=no +DHCP_HOSTNAME="svata-pulec" diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-dhcp6-only b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-dhcp6-only new file mode 100644 index 00000000..de03e044 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-dhcp6-only @@ -0,0 +1,11 @@ +DEVICE="eth0" +ONBOOT=no +TYPE=Ethernet +DEFROUTE=yes +PEERDNS=yes +PEERROUTES=yes +IPV6INIT=yes +IPV6_AUTOCONF=no +DHCPV6C=yes +HWADDR=00:13:20:F5:F5:E4 + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-dhcpv6-hostname-fallback b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-dhcpv6-hostname-fallback new file mode 100644 index 00000000..d38e762e --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-dhcpv6-hostname-fallback @@ -0,0 +1,12 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=dhcp +ONBOOT=yes +IPV6INIT=yes +IPV6_AUTOCONF=yes +USERCTL=yes +NM_CONTROLLED=yes +PEERDNS=no +DHCP_HOSTNAME="fully.qualified.domain" diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-global-gateway b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-global-gateway new file mode 100644 index 00000000..98d91053 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-global-gateway @@ -0,0 +1,14 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=none +ONBOOT=yes +USERCTL=yes +IPV6INIT=no +NM_CONTROLLED=yes +DNS1=4.2.2.1 +DNS2=4.2.2.2 +IPADDR=192.168.1.5 +PREFIX=24 + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-global-gateway-ignore b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-global-gateway-ignore new file mode 100644 index 00000000..bb81399e --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-global-gateway-ignore @@ -0,0 +1,8 @@ +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=dhcp +ONBOOT=yes +USERCTL=yes +IPV6INIT=no + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-ipv4-manual-1 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-ipv4-manual-1 new file mode 100644 index 00000000..db09afdb --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-ipv4-manual-1 @@ -0,0 +1,14 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=none +IPADDR0=1.2.3.4 +PREFIX0=24 +IPADDR1=9.8.7.6 +PREFIX1=16 +IPADDR2=3.3.3.3 +PREFIX2=8 +GATEWAY=1.1.1.1 +ACD_TIMEOUT=2000 +ARPING_WAIT=1 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-ipv4-manual-2 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-ipv4-manual-2 new file mode 100644 index 00000000..6972e279 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-ipv4-manual-2 @@ -0,0 +1,13 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=none +IPADDR=1.2.3.4 +PREFIX=24 +IPADDR2=9.8.7.6 +PREFIX2=16 +IPADDR3=3.3.3.3 +PREFIX3=8 +ACD_TIMEOUT=2000 +ARPING_WAIT=1 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-ipv4-manual-3 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-ipv4-manual-3 new file mode 100644 index 00000000..d9065994 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-ipv4-manual-3 @@ -0,0 +1,13 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=none +IPADDR2=1.2.3.4 +PREFIX2=24 +IPADDR3=9.8.7.6 +PREFIX3=16 +IPADDR4=3.3.3.3 +PREFIX4=8 +ACD_TIMEOUT=2000 +ARPING_WAIT=1 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-ipv4-manual-4 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-ipv4-manual-4 new file mode 100644 index 00000000..935267f7 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-ipv4-manual-4 @@ -0,0 +1,13 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=none +IPADDR=1.2.3.4 +PREFIX=24 +IPADDR1=9.8.7.6 +PREFIX1=16 +IPADDR2=3.3.3.3 +PREFIX2=8 +ACD_TIMEOUT=2000 +ARPING_WAIT=1 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-ipv6-manual b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-ipv6-manual new file mode 100644 index 00000000..45db0e4c --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-ipv6-manual @@ -0,0 +1,19 @@ +# Intel Corporation 82567LM Gigabit Network Connection +TYPE=Ethernet +DEVICE=eth2 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=dhcp +ONBOOT=yes +USERCTL=yes +NM_CONTROLLED=yes +PEERDNS=yes +DNS1=10.2.0.4 +DNS2=10.2.0.5 +DNS3=1:2:3:4::a +DNS4=1:2:3:4::b +DOMAIN="lorem.com ipsum.org dolor.edu" +IPV6INIT=yes +IPV6_AUTOCONF=no +IPV6ADDR="1001:abba::1234/56" +IPV6ADDR_SECONDARIES="2001:abba::2234/64 3001:abba::3234/96" +IPV6_FAILURE_FATAL=no diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-ipv6-only b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-ipv6-only new file mode 100644 index 00000000..94189064 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-ipv6-only @@ -0,0 +1,14 @@ +# Intel Corporation 82567LM Gigabit Network Connection +TYPE=Ethernet +DEVICE=eth2 +HWADDR=00:11:22:33:44:ee +ONBOOT=yes +USERCTL=yes +NM_CONTROLLED=yes +PEERDNS=yes +DNS1=1:2:3:4::a +IPV6_DOMAIN="lorem.com ipsum.org dolor.edu" +IPV6INIT=yes +IPV6_AUTOCONF=no +IPV6ADDR="1001:abba::1234/56" + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-ipv6-only-1 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-ipv6-only-1 new file mode 100644 index 00000000..95f8a8ed --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-ipv6-only-1 @@ -0,0 +1,16 @@ +IPADDR= +GATEWAY= +NETMASK= +BOOTPROTO=static +TYPE=Ethernet +DEVICE=eth2 +HWADDR=00:11:22:33:44:ee +ONBOOT=yes +USERCTL=yes +NM_CONTROLLED=yes +PEERDNS=yes +DNS1=1:2:3:4::a +DOMAIN="lorem.com ipsum.org dolor.edu" +IPV6INIT=yes +IPV6_AUTOCONF=no +IPV6ADDR="1001:abba::1234/56" diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-never-default b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-never-default new file mode 100644 index 00000000..12d5b5e6 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-never-default @@ -0,0 +1,11 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth4 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=dhcp +ONBOOT=yes +USERCTL=yes +NM_CONTROLLED=yes +PEERDNS=yes +IPV6INIT=yes +IPV6_AUTOCONF=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-obsolete-gateway-n b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-obsolete-gateway-n new file mode 100644 index 00000000..2190a995 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-obsolete-gateway-n @@ -0,0 +1,13 @@ +# GATEWAY<N> is obsolete, but we read it for backwards compatibility + +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=none +ONBOOT=yes + +# manual IP +IPADDR1=1.2.3.4 +PREFIX1=24 +GATEWAY1=1.1.1.1 + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-qeth-static b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-qeth-static new file mode 100644 index 00000000..4719de21 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-qeth-static @@ -0,0 +1,13 @@ +# IBM QETH +DEVICE=eth1 +BOOTPROTO=static +IPADDR=192.168.70.87 +NETMASK=255.255.255.0 +ONBOOT=yes +NETTYPE=qeth +SUBCHANNELS=0.0.0600,0.0.0601,0.0.0602 +TYPE=Ethernet +PORTNAME=OSAPORT +OPTIONS='layer2=1 portno=0' +MACADDR=02:00:00:23:65:1a + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-shared-plus-ip b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-shared-plus-ip new file mode 100644 index 00000000..5098aef7 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-shared-plus-ip @@ -0,0 +1,19 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=shared +ONBOOT=no +IPV6INIT=yes + +# additional IPs +IPADDR=10.20.30.5 +PREFIX=24 +GATEWAY=1.1.1.1 + +# these are ignored for shared method +IPADDR1=6.7.8.9 +PREFIX1=16 +IPADDR2=3.3.3.3 +PREFIX2=24 + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-static b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-static new file mode 100644 index 00000000..34acf9fe --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-static @@ -0,0 +1,22 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=none +ONBOOT=yes +USERCTL=yes +MTU=1492 +NM_CONTROLLED=yes +DNS1=4.2.2.1 +DNS2=4.2.2.2 +IPADDR=192.168.1.5 +NETMASK=255.255.255.0 +GATEWAY=192.168.1.1 +IPV6INIT=yes +IPV6_AUTOCONF=no +IPV6ADDR=dead:beaf::1 +IPV6ADDR_SECONDARIES="dead:beaf::2/56" +DNS3=1:2:3:4::a +DNS4=1:2:3:4::b +RES_OPTIONS= +IPV6_RES_OPTIONS= diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-static-bootproto b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-static-bootproto new file mode 100644 index 00000000..a01f6558 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-static-bootproto @@ -0,0 +1,16 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=static +ONBOOT=yes +USERCTL=yes +IPV6INIT=no +MTU=1492 +NM_CONTROLLED=yes +DNS1=4.2.2.1 +DNS2=4.2.2.2 +IPADDR=192.168.1.5 +NETMASK=255.255.255.0 +GATEWAY=192.168.1.1 +RES_OPTIONS= diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-static-no-prefix-16 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-static-no-prefix-16 new file mode 100644 index 00000000..07999038 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-static-no-prefix-16 @@ -0,0 +1,14 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=none +ONBOOT=yes +USERCTL=yes +MTU=1492 +NM_CONTROLLED=yes +DNS1=4.2.2.1 +DNS2=4.2.2.2 +IPADDR=172.16.3.4 +GATEWAY=172.16.3.1 + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-static-no-prefix-24 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-static-no-prefix-24 new file mode 100644 index 00000000..688143cd --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-static-no-prefix-24 @@ -0,0 +1,14 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=none +ONBOOT=yes +USERCTL=yes +MTU=1492 +NM_CONTROLLED=yes +DNS1=4.2.2.1 +DNS2=4.2.2.2 +IPADDR=192.168.1.5 +GATEWAY=192.168.1.1 + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-static-no-prefix-8 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-static-no-prefix-8 new file mode 100644 index 00000000..0433c62a --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-static-no-prefix-8 @@ -0,0 +1,14 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=none +ONBOOT=yes +USERCTL=yes +MTU=1492 +NM_CONTROLLED=yes +DNS1=4.2.2.1 +DNS2=4.2.2.2 +IPADDR=10.11.12.13 +GATEWAY=10.0.0.1 + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-static-routes b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-static-routes new file mode 100644 index 00000000..7faf49bd --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-static-routes @@ -0,0 +1,15 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=none +ONBOOT=yes +USERCTL=yes +IPV6INIT=no +MTU=1492 +NM_CONTROLLED=yes +DNS1=4.2.2.1 +DNS2=4.2.2.2 +IPADDR=192.168.1.5 +NETMASK=255.255.255.0 +GATEWAY=192.168.1.1 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-static-routes-legacy b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-static-routes-legacy new file mode 100644 index 00000000..7faf49bd --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-static-routes-legacy @@ -0,0 +1,15 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=none +ONBOOT=yes +USERCTL=yes +IPV6INIT=no +MTU=1492 +NM_CONTROLLED=yes +DNS1=4.2.2.1 +DNS2=4.2.2.2 +IPADDR=192.168.1.5 +NETMASK=255.255.255.0 +GATEWAY=192.168.1.1 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-unknown-ethtool-opt b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-unknown-ethtool-opt new file mode 100644 index 00000000..861dd41f --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-unknown-ethtool-opt @@ -0,0 +1,22 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=none +ONBOOT=yes +USERCTL=yes +MTU=1492 +NM_CONTROLLED=yes +DNS1=4.2.2.1 +DNS2=4.2.2.2 +IPADDR=192.168.1.5 +NETMASK=255.255.255.0 +GATEWAY=192.168.1.1 +IPV6INIT=yes +IPV6_AUTOCONF=no +IPV6ADDR=dead:beaf::1 +IPV6ADDR_SECONDARIES="dead:beaf::2/56" +DNS3=1:2:3:4::a +DNS4=1:2:3:4::b +RES_OPTIONS= +ETHTOOL_OPTS="unknown1 wol apgs sopass 00:11:22:33:44:55 unkwnown2 opt2 unknown3" diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-wake-on-lan b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-wake-on-lan new file mode 100644 index 00000000..1dfc9a43 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-wired-wake-on-lan @@ -0,0 +1,22 @@ +# Intel Corporation 82540EP Gigabit Ethernet Controller (Mobile) +TYPE=Ethernet +DEVICE=eth0 +HWADDR=00:11:22:33:44:ee +BOOTPROTO=none +ONBOOT=yes +USERCTL=yes +MTU=1492 +NM_CONTROLLED=yes +DNS1=4.2.2.1 +DNS2=4.2.2.2 +IPADDR=192.168.1.5 +NETMASK=255.255.255.0 +GATEWAY=192.168.1.1 +IPV6INIT=yes +IPV6_AUTOCONF=no +IPV6ADDR=dead:beaf::1 +IPV6ADDR_SECONDARIES="dead:beaf::2/56" +DNS3=1:2:3:4::a +DNS4=1:2:3:4::b +RES_OPTIONS= +ETHTOOL_OPTS="speed 100 duplex full wol apgs sopass 00:11:22:33:44:55 autoneg off" diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-1 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-1 new file mode 100644 index 00000000..2af1daf3 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-1 @@ -0,0 +1,8 @@ +FOO='val + bar=3' +wrong line + F2=b + F3='b +XXA=adf' + XXA2=val2 +' diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-1.expected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-1.expected new file mode 100644 index 00000000..7f154073 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-1.expected @@ -0,0 +1,12 @@ +FOO= +#NM: FOO='val +bar= +#NM: bar=3' +#NM: wrong line + F2=b +F3= +#NM: F3='b +XXA= +#NM: XXA=adf' + XXA2=val2 +#NM: ' diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-2 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-2 new file mode 100644 index 00000000..850149b2 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-2 @@ -0,0 +1,3 @@ +FOO=' +BAR=a +' diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-2.expected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-2.expected new file mode 100644 index 00000000..6ec53c17 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-2.expected @@ -0,0 +1,4 @@ +FOO= +#NM: FOO=' +BAR=a +#NM: ' diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-3 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-3 new file mode 100644 index 00000000..3d198e00 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-3 @@ -0,0 +1,3 @@ +FOO=' +BAR=" +' diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-3.expected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-3.expected new file mode 100644 index 00000000..d2b27eb3 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-3.expected @@ -0,0 +1,5 @@ +FOO= +#NM: FOO=' +BAR= +#NM: BAR=" +#NM: ' diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4 new file mode 100644 index 00000000..f834464e --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4 @@ -0,0 +1,36 @@ +# test what happens with multiple defines of a name. +# +# Note that svGetValue() will return "l4x", which +# isn't correct in terms of shell-parsing. But we +# don't consider only line-by-line, thus this is +# expected. +# +# Also note that setting IPADDR will replace the last +# occurrence, and delete all previous once. + +#L1 +IPADDR=l2 + +#L2 +IPADDR=l3 + +METRIC1='' +METRIC2=$'\U0x' +METRIC3=$'x\U0' + +#L4 +IPADDR=' +IPADDR=l4x +' + +#Lx-1 +IPADDR2=not-visible +#Lx-2 +IPADDR2='invalid +#Lx-3 + +#Ly-1 +IPADDR3='invalid +#Ly-2 +IPADDR3=name3-value +#Ly-3 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4.expected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4.expected new file mode 100644 index 00000000..040ddc9d --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-write-unknown-4.expected @@ -0,0 +1,31 @@ +# test what happens with multiple defines of a name. +# +# Note that svGetValue() will return "l4x", which +# isn't correct in terms of shell-parsing. But we +# don't consider only line-by-line, thus this is +# expected. +# +# Also note that setting IPADDR will replace the last +# occurrence, and delete all previous once. + +#L1 + +#L2 + +METRIC1='' +METRIC2=$'\U0x' +METRIC3=$'x\U0' + +#L4 +IPADDR=set-by-test1 +#NM: ' + +#Lx-1 +#Lx-2 +IPADDR2=set-by-test2 +#Lx-3 + +#Ly-1 +#Ly-2 +IPADDR3=set-by-test3 +#Ly-3 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test_write_wired_auto_negotiate_on.cexpected b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test_write_wired_auto_negotiate_on.cexpected new file mode 100644 index 00000000..42608576 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test_write_wired_auto_negotiate_on.cexpected @@ -0,0 +1,15 @@ +TYPE=Ethernet +PROXY_METHOD=none +BROWSER_ONLY=no +ETHTOOL_OPTS="autoneg on ; -K net0 rxvlan off tx on" +BOOTPROTO=dhcp +DEFROUTE=yes +IPV4_FAILURE_FATAL=no +IPV6INIT=yes +IPV6_AUTOCONF=yes +IPV6_DEFROUTE=yes +IPV6_FAILURE_FATAL=no +IPV6_ADDR_GEN_MODE=stable-privacy +NAME="Test Write Wired Auto-Negotiate" +UUID=${UUID} +ONBOOT=yes diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-dynamic-wep-leap b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-dynamic-wep-leap new file mode 100644 index 00000000..6936f2e0 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-dynamic-wep-leap @@ -0,0 +1,2 @@ +IEEE_8021X_PASSWORD="foobar baz" + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-leap b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-leap new file mode 100644 index 00000000..fe78177e --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-leap @@ -0,0 +1 @@ +IEEE_8021X_PASSWORD="foobarblah" diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-sae b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-sae new file mode 100644 index 00000000..5a9569ed --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-sae @@ -0,0 +1 @@ +WPA_PSK="The king is dead." diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wep b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wep new file mode 100644 index 00000000..0bd766c2 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wep @@ -0,0 +1 @@ +KEY=0123456789abcdef0123456789 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wep-104-ascii b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wep-104-ascii new file mode 100644 index 00000000..f5d532b2 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wep-104-ascii @@ -0,0 +1 @@ +KEY1=s:LoremIpsumSit diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wep-40-ascii b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wep-40-ascii new file mode 100644 index 00000000..b0d14708 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wep-40-ascii @@ -0,0 +1 @@ +KEY1=s:Lorem diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wep-adhoc b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wep-adhoc new file mode 100644 index 00000000..0bd766c2 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wep-adhoc @@ -0,0 +1 @@ +KEY=0123456789abcdef0123456789 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wep-eap-ttls-chap b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wep-eap-ttls-chap new file mode 100644 index 00000000..6936f2e0 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wep-eap-ttls-chap @@ -0,0 +1,2 @@ +IEEE_8021X_PASSWORD="foobar baz" + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wep-passphrase b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wep-passphrase new file mode 100644 index 00000000..d45c0ea8 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wep-passphrase @@ -0,0 +1 @@ +KEY_PASSPHRASE1="foobar222blahblah" diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wpa-eap-tls b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wpa-eap-tls new file mode 100644 index 00000000..0c3bc1e1 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wpa-eap-tls @@ -0,0 +1,2 @@ +IEEE_8021X_PRIVATE_KEY_PASSWORD="test1" + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wpa-eap-ttls-tls b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wpa-eap-ttls-tls new file mode 100644 index 00000000..b6256b95 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wpa-eap-ttls-tls @@ -0,0 +1,2 @@ +IEEE_8021X_INNER_PRIVATE_KEY_PASSWORD="test1" + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wpa-psk b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wpa-psk new file mode 100644 index 00000000..d7813b2f --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wpa-psk @@ -0,0 +1,2 @@ +WPA_PSK="I wonder what the king is doing tonight?" + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wpa-psk-2 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wpa-psk-2 new file mode 100644 index 00000000..995721dd --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wpa-psk-2 @@ -0,0 +1,2 @@ +WPA_PSK="They're really saying I love you. >>\`<< '" + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wpa-psk-adhoc b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wpa-psk-adhoc new file mode 100644 index 00000000..d7813b2f --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wpa-psk-adhoc @@ -0,0 +1,2 @@ +WPA_PSK="I wonder what the king is doing tonight?" + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wpa-psk-hex b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wpa-psk-hex new file mode 100644 index 00000000..d0576a8d --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wpa-psk-hex @@ -0,0 +1,2 @@ +WPA_PSK=1da190379817bc360dda52e85c388c439a21ea5c7bf819c64e9da051807deae6 + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wpa-psk-unquoted b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wpa-psk-unquoted new file mode 100644 index 00000000..9a47196a --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wpa-psk-unquoted @@ -0,0 +1,2 @@ +WPA_PSK=54336845e2f3f321c4c7 + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wpa-psk-unquoted2 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wpa-psk-unquoted2 new file mode 100644 index 00000000..347bb85e --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wifi-wpa-psk-unquoted2 @@ -0,0 +1,2 @@ +WPA_PSK="a5d4d45e78e1455d8e6124e81ea137f9a5d4d45e78e1455d8e6124e81ea137f9" + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wired-802-1x-password-raw b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wired-802-1x-password-raw new file mode 100644 index 00000000..d29a4289 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wired-802-1x-password-raw @@ -0,0 +1 @@ +IEEE_8021X_PIN=hallo2 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wired-8021x-peap-mschapv2 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wired-8021x-peap-mschapv2 new file mode 100644 index 00000000..6936f2e0 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/keys-test-wired-8021x-peap-mschapv2 @@ -0,0 +1,2 @@ +IEEE_8021X_PASSWORD="foobar baz" + diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/network-test-wired-defroute-no-gatewaydev-yes b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/network-test-wired-defroute-no-gatewaydev-yes new file mode 100644 index 00000000..0d6a302f --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/network-test-wired-defroute-no-gatewaydev-yes @@ -0,0 +1,2 @@ +GATEWAYDEV=eth0 +IPV6_DEFAULTDEV=eth0 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/network-test-wired-global-gateway b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/network-test-wired-global-gateway new file mode 100644 index 00000000..7987d105 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/network-test-wired-global-gateway @@ -0,0 +1 @@ +GATEWAY=192.168.1.2 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/network-test-wired-global-gateway-ignore b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/network-test-wired-global-gateway-ignore new file mode 100644 index 00000000..7987d105 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/network-test-wired-global-gateway-ignore @@ -0,0 +1 @@ +GATEWAY=192.168.1.2 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/network-test-wired-never-default b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/network-test-wired-never-default new file mode 100644 index 00000000..4347405e --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/network-test-wired-never-default @@ -0,0 +1,4 @@ +GATEWAYDEV=eth0 +# when devices in IPV6_DEFAULTDEV and IPV6_DEFAULTGW don't match the one in IPV6_DEFAULTGW is preferred +IPV6_DEFAULTDEV=eth4 +IPV6_DEFAULTGW=2001::1234%eth0 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/route-test-static-routes-legacy b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/route-test-static-routes-legacy new file mode 100644 index 00000000..c9e422e7 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/route-test-static-routes-legacy @@ -0,0 +1,4 @@ +1.2.3.0/24 via 222.173.190.239 metric 0 +3.2.1.0/24 via 202.254.171.190 metric 77 +7.7.7.7/32 via 10.0.2.2 metric 11 +8.8.8.8/32 metric 12 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/route-test-wired-static-routes b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/route-test-wired-static-routes new file mode 100644 index 00000000..9c05417e --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/route-test-wired-static-routes @@ -0,0 +1,19 @@ +ADDRESS0=11.22.33.0 +NETMASK0=255.255.255.0 +GATEWAY0=192.168.1.5 + +ADDRESS1=44.55.66.77 +NETMASK1=255.255.255.255 +GATEWAY1=192.168.1.7 +METRIC1=3 +OPTIONS1="mtu lock 9000 cwnd 12 src 1.1.1.1 tos 0x28 window 30000 scope 10 initcwnd lock 13 initrwnd 14" + +ADDRESS2=44.55.66.78 +NETMASK2=255.255.255.255 +GATEWAY2=192.168.1.8 +METRIC2=3 +OPTIONS2="mtu lock 9000 cwnd 12 src 1.1.1.1 tos 0x28 onlink window 30000 initcwnd lock 13 initrwnd 14 scope link" + +ADDRESS3=1.2.3.4 +NETMASK3=255.255.255.255 +OPTIONS3="local scope host" diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/route-test-wired-static-routes-legacy b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/route-test-wired-static-routes-legacy new file mode 100644 index 00000000..1fef7e97 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/route-test-wired-static-routes-legacy @@ -0,0 +1,9 @@ +# Test route file in legacy format; i.e. lines passed as argumet to "ip route add" + + +21.31.41.0/24 via 9.9.9.9 metric 1 + via 8.8.8.8 to 32.42.52.62 + 43.53.0.0/16 metric 3 via 7.7.7.7 dev eth2 cwnd 14 mtu lock 9000 initrwnd 20 window lock 10000 initcwnd lock 42 src 1.2.3.4 + +7.7.7.8/32 via (null) metric 18 +local 1.2.3.4 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/route6-test-wired-ipv6-manual b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/route6-test-wired-ipv6-manual new file mode 100644 index 00000000..8bdf0acf --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/route6-test-wired-ipv6-manual @@ -0,0 +1,9 @@ +9876::1234/96 via 9876::7777 metric 2 + +# default route is ignored by ifcfg-rh reader, because NM handles it internally +default via dead::beaf + +# routes without "via" are valid +abbe::cafe/64 metric 777 + +aaaa::cccc/64 from 1111::2222/48 via 3333::4444 src 5555::6666 mtu lock 1450 cwnd 13 diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/test1_key_and_cert.pem b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/test1_key_and_cert.pem new file mode 100644 index 00000000..dec9aa1b --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/test1_key_and_cert.pem @@ -0,0 +1,118 @@ +-----BEGIN RSA PRIVATE KEY----- +Proc-Type: 4,ENCRYPTED +DEK-Info: DES-EDE3-CBC,4DE0615F23D82107 + +QPNCO5Dobvz9dDhN32KkZRoEifW+HDm2PCbRQhKDiscGwB6LgypvVjHNsZiFKwzz +L4R51UqgQeJx7GSGJqE626e9z9J+UNBhop02aOO2X0eSPdvBzr/uJ6Umiyr1xqD7 +zWf7u9l5kXElDJRhK+87GMBewp4Ie9NeXDjhF8hzC5Kiulen4AH3AYnfH3S7DimU +h8GFMg8inrudrTbcjBhCdPeHG2jCygOxw3InRFz7uaN6LIhOaPQvmvpP4Cc1WRnW +ZPq9o+eU3fPWPD5t+Op/VzYLvKwgBy/yK1rQXUm6ZMO7MhhRJ94ZCsJv+nVWpJlv +QyBlxDKxwfkfYbDELdnnDQdHdMbKatLqa0KhSkgpp8LywBtanPz731tyT0r7b3na +eLdra59lRU7ZQLPEdS3lPZd2O/KQvWf8wbg7MjXS9LxQ7R5HOPu6DNJlwXVZBmmo +cAfu2q8ubU2IePvWLD1GOrBi6hE9TiGvFJkw+wBK+t72sz3njv9Xm/zlxruaEk5m +RW/kybU3FP4PtjriBbskz3/VZaaxuRN7OoOYTkmyHmG1ADgcRUV6fea19qqsBlN8 +xb+SRtoH28oT/JVWU5neE2dbNzk5LeVO+w70NNdR5s5xqkBhbGGaJxvXwNP4ltFr +T06SMh8znOLKwWB00aRtwfU7jOwR3mOleQO4ugIHmau3zp1TqzAHW8XtpuV7qVeI +ESZOZuf0vW43BtNzgLXt1+r+bmsMsRwhnyomL9M0TUyyBdVYY9GkzTG9pOESheRo +RSvAZ8qKGUliTpgBcbt2v1+NqkszcHa6FxuvS8YU4uo5/GqsgTxHTNIB232hIrrZ +EIm6QL9TC5oFXMjy6UNqoCm5Nb8DBJ6aErt7pt7aoktqUW3O3QIzQT3IbZ4nAcTt +lVF4d7j29I9t7bcC8GOVU1neilguZUss4ghJg9x4zI5UZdR7hZ8fbFT47TyxB+j5 +r0YdmjbjVTaSyaN2JGh1wvb4TzawGNVx/U2EJE16HigOtPfsfQRJ3x+FROKBdVa4 +aIFYXkRBeIPxX6n9pcw0lBCsnXo6/5iTjQSk2VqO3rHO/wyWiEjNczhL33dY2A8W +GG5ECMO5SqXZHQQzpABqK94dxe3UC8aEESO5NhEqDuV7qQGol0qPKrUA3wb0jb2e +DrejJ9HS2m1SUDmjpvvmEGy6GN7CRibbKt5rNZdJNNvWArOF5d0F6wkixQLl73oE +lq5gLQQk9n7ClleKLhlQpBCorxilBbzmSUekkJLi0eaZiBBFWBX9udqnUZloXTgO +8qwuO8K/GPR9Jy1/UH2Vh1H+wivaqKTVgEb0NotzgzECgTEFKJafl7rUNs1OZRZ3 +VBjevi6+iDpxVFgF71kXfdUC4ph0E1XDl0ja2rrKQGivMkUhWJ57+4EV5+hBkAnt +G0RV45NwHXLrK2bd8F9PlRk2XHW6mIcFRXsW1DjeBhk/sQjvlO9R01GRSgcXtekJ +tmX17FWrMrzXHpvy1IC3fk4RVnSjpzQ8O+17YE8/la9wVaeZZzHyYFmMT7VXjIhW +QozJQ0vJ2jxJRh5GYn3tpJzdaeRfvTBik0pChNdUTnWP+BJ35xoCTs8iwJbmgVZ1 +-----END RSA PRIVATE KEY----- +Certificate: + Data: + Version: 3 (0x2) + Serial Number: 1 (0x1) + Signature Algorithm: md5WithRSAEncryption + Issuer: C=US, ST=Berkshire, L=Newbury, O=My Company Ltd, OU=Testing, CN=test/emailAddress=test@test.com + Validity + Not Before: Mar 10 15:13:16 2009 GMT + Not After : Mar 8 15:13:16 2019 GMT + Subject: C=US, ST=Berkshire, O=My Company Ltd, OU=Testing, CN=test1/emailAddress=test@test.com + Subject Public Key Info: + Public Key Algorithm: rsaEncryption + RSA Public Key: (2048 bit) + Modulus (2048 bit): + 00:cd:34:b1:2e:b0:04:c6:f4:2b:a2:c0:a0:39:7a: + 82:ed:96:c4:f7:19:83:91:5c:b4:e7:9c:de:ec:48: + ec:2d:e4:51:08:26:42:ac:d3:98:26:7a:72:f7:49: + c2:9e:66:05:c6:47:29:fe:3b:ac:6b:af:6f:5e:a8: + 03:5a:73:33:ba:19:03:00:35:f5:00:bc:a8:be:14: + ce:46:69:e3:6d:ed:34:37:85:55:87:62:b3:b7:c9: + c0:cc:9a:aa:61:05:5b:cd:a2:17:42:d3:e5:6f:1c: + 60:8d:c2:15:41:46:f8:12:54:d0:38:57:e1:fd:8d: + 44:c8:fb:56:b3:b9:6c:e9:f8:9e:21:11:57:1b:8b: + f9:cf:e3:17:e7:d8:fd:ac:d1:01:c6:92:30:f3:2d: + c9:d6:c1:f0:3d:fd:ca:30:dd:75:74:e7:d1:6b:75: + d8:c5:4d:43:61:fe:f6:ad:7e:4c:63:7c:03:17:a2: + 06:8f:d0:8b:69:d3:7a:07:0f:0b:a2:cf:0c:70:38: + ba:cc:55:35:60:84:58:d8:d2:be:1f:ef:76:a9:ba: + ae:6a:dc:08:97:80:de:42:00:b7:d4:ce:9a:b0:36: + 2a:c7:6f:45:04:7c:ea:41:19:d8:b9:19:04:1f:11: + a9:22:80:bd:69:08:15:0d:3c:de:cd:7e:88:6c:0f: + a3:43 + Exponent: 65537 (0x10001) + X509v3 extensions: + X509v3 Basic Constraints: + CA:FALSE + Netscape Comment: + OpenSSL Generated Certificate + X509v3 Subject Key Identifier: + CE:03:7E:EF:E7:DE:C9:87:BF:DE:56:F4:C8:A3:40:F6:C8:6F:05:8C + X509v3 Authority Key Identifier: + keyid:B8:35:37:32:BE:CF:4F:79:F5:7B:74:B2:F2:10:5A:BA:80:C5:6A:10 + DirName:/C=US/ST=Berkshire/L=Newbury/O=My Company Ltd/OU=Testing/CN=test/emailAddress=test@test.com + serial:EB:E7:64:FB:79:F7:22:19 + + Signature Algorithm: md5WithRSAEncryption + 7a:20:93:63:40:73:7d:33:01:2e:c0:13:52:a4:a7:e1:4d:82: + f4:fb:b2:7b:d0:2b:5a:3f:0e:3c:28:61:71:ab:01:4d:fe:89: + b5:cd:2f:97:59:93:53:9d:51:86:48:dd:b9:e4:73:5e:22:0b: + 12:0d:25:39:76:16:44:06:0c:40:45:21:6b:a6:b1:e0:bf:76: + 1b:36:f3:1e:41:82:57:d9:59:b7:60:40:43:1c:1d:79:f6:48: + 32:5c:4e:e2:06:89:96:41:d2:54:1f:4a:6f:f6:78:a5:3c:02: + 85:21:e2:65:e1:8a:6d:24:19:95:f8:c0:35:ab:bd:ff:3d:f1: + fb:50:2d:30:1e:67:a6:7c:50:f9:d5:77:66:77:5a:14:0f:5c: + cd:21:09:9b:a3:92:57:19:dd:01:a4:18:c5:f9:70:e4:17:43: + 8d:b1:e6:61:e9:50:89:83:4f:ce:a4:57:68:58:40:70:ae:71: + 1c:47:66:d2:30:54:50:ea:3a:87:32:64:3b:18:42:fe:5a:19: + 07:64:f7:f1:b1:10:07:fd:a7:d2:a7:a8:05:79:5b:25:ba:69: + 7b:1a:3e:b1:3e:e4:17:17:01:ba:eb:54:ae:83:00:ed:66:62: + 8d:c0:3e:8a:b4:27:5f:e9:01:ce:20:c3:34:a9:28:c0:6f:c7: + 3b:65:fe:f9 +-----BEGIN CERTIFICATE----- +MIIEojCCA4qgAwIBAgIBATANBgkqhkiG9w0BAQQFADCBizELMAkGA1UEBhMCVVMx +EjAQBgNVBAgTCUJlcmtzaGlyZTEQMA4GA1UEBxMHTmV3YnVyeTEXMBUGA1UEChMO +TXkgQ29tcGFueSBMdGQxEDAOBgNVBAsTB1Rlc3RpbmcxDTALBgNVBAMTBHRlc3Qx +HDAaBgkqhkiG9w0BCQEWDXRlc3RAdGVzdC5jb20wHhcNMDkwMzEwMTUxMzE2WhcN +MTkwMzA4MTUxMzE2WjB6MQswCQYDVQQGEwJVUzESMBAGA1UECBMJQmVya3NoaXJl +MRcwFQYDVQQKEw5NeSBDb21wYW55IEx0ZDEQMA4GA1UECxMHVGVzdGluZzEOMAwG +A1UEAxMFdGVzdDExHDAaBgkqhkiG9w0BCQEWDXRlc3RAdGVzdC5jb20wggEiMA0G +CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDNNLEusATG9CuiwKA5eoLtlsT3GYOR +XLTnnN7sSOwt5FEIJkKs05gmenL3ScKeZgXGRyn+O6xrr29eqANaczO6GQMANfUA +vKi+FM5GaeNt7TQ3hVWHYrO3ycDMmqphBVvNohdC0+VvHGCNwhVBRvgSVNA4V+H9 +jUTI+1azuWzp+J4hEVcbi/nP4xfn2P2s0QHGkjDzLcnWwfA9/cow3XV059FrddjF +TUNh/vatfkxjfAMXogaP0Itp03oHDwuizwxwOLrMVTVghFjY0r4f73apuq5q3AiX +gN5CALfUzpqwNirHb0UEfOpBGdi5GQQfEakigL1pCBUNPN7NfohsD6NDAgMBAAGj +ggEfMIIBGzAJBgNVHRMEAjAAMCwGCWCGSAGG+EIBDQQfFh1PcGVuU1NMIEdlbmVy +YXRlZCBDZXJ0aWZpY2F0ZTAdBgNVHQ4EFgQUzgN+7+feyYe/3lb0yKNA9shvBYww +gcAGA1UdIwSBuDCBtYAUuDU3Mr7PT3n1e3Sy8hBauoDFahChgZGkgY4wgYsxCzAJ +BgNVBAYTAlVTMRIwEAYDVQQIEwlCZXJrc2hpcmUxEDAOBgNVBAcTB05ld2J1cnkx +FzAVBgNVBAoTDk15IENvbXBhbnkgTHRkMRAwDgYDVQQLEwdUZXN0aW5nMQ0wCwYD +VQQDEwR0ZXN0MRwwGgYJKoZIhvcNAQkBFg10ZXN0QHRlc3QuY29tggkA6+dk+3n3 +IhkwDQYJKoZIhvcNAQEEBQADggEBAHogk2NAc30zAS7AE1Kkp+FNgvT7snvQK1o/ +DjwoYXGrAU3+ibXNL5dZk1OdUYZI3bnkc14iCxINJTl2FkQGDEBFIWumseC/dhs2 +8x5BglfZWbdgQEMcHXn2SDJcTuIGiZZB0lQfSm/2eKU8AoUh4mXhim0kGZX4wDWr +vf898ftQLTAeZ6Z8UPnVd2Z3WhQPXM0hCZujklcZ3QGkGMX5cOQXQ42x5mHpUImD +T86kV2hYQHCucRxHZtIwVFDqOocyZDsYQv5aGQdk9/GxEAf9p9KnqAV5WyW6aXsa +PrE+5BcXAbrrVK6DAO1mYo3APoq0J1/pAc4gwzSpKMBvxztl/vk= +-----END CERTIFICATE----- diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/test_ca_cert.pem b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/test_ca_cert.pem new file mode 100644 index 00000000..ef1be20d --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/test_ca_cert.pem @@ -0,0 +1,27 @@ +-----BEGIN CERTIFICATE----- +MIIEjzCCA3egAwIBAgIJAOvnZPt59yIZMA0GCSqGSIb3DQEBBQUAMIGLMQswCQYD +VQQGEwJVUzESMBAGA1UECBMJQmVya3NoaXJlMRAwDgYDVQQHEwdOZXdidXJ5MRcw +FQYDVQQKEw5NeSBDb21wYW55IEx0ZDEQMA4GA1UECxMHVGVzdGluZzENMAsGA1UE +AxMEdGVzdDEcMBoGCSqGSIb3DQEJARYNdGVzdEB0ZXN0LmNvbTAeFw0wOTAzMTAx +NTEyMTRaFw0xOTAzMDgxNTEyMTRaMIGLMQswCQYDVQQGEwJVUzESMBAGA1UECBMJ +QmVya3NoaXJlMRAwDgYDVQQHEwdOZXdidXJ5MRcwFQYDVQQKEw5NeSBDb21wYW55 +IEx0ZDEQMA4GA1UECxMHVGVzdGluZzENMAsGA1UEAxMEdGVzdDEcMBoGCSqGSIb3 +DQEJARYNdGVzdEB0ZXN0LmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC +ggEBAKot9j+/+CX1/gZLgJHIXCRgCItKLGnf7qGbgqB9T2ACBqR0jllKWwDKrcWU +xjXNIc+GF9Wnv+lX6G0Okn4Zt3/uRNobL+2b/yOF7M3Td3/9W873zdkQQX930YZc +Rr8uxdRPP5bxiCgtcw632y21sSEbG9mjccAUnV/0jdvfmMNj0i8gN6E0fMBiJ9S3 +FkxX/KFvt9JWE9CtoyL7ki7UIDq+6vj7Gd5N0B3dOa1y+rRHZzKlJPcSXQSEYUS4 +HmKDwiKSVahft8c4tDn7KPi0vex91hlgZVd3usL2E/Vq7o5D9FAZ5kZY0AdFXwdm +J4lO4Mj7ac7GE4vNERNcXVIX59sCAwEAAaOB8zCB8DAdBgNVHQ4EFgQUuDU3Mr7P +T3n1e3Sy8hBauoDFahAwgcAGA1UdIwSBuDCBtYAUuDU3Mr7PT3n1e3Sy8hBauoDF +ahChgZGkgY4wgYsxCzAJBgNVBAYTAlVTMRIwEAYDVQQIEwlCZXJrc2hpcmUxEDAO +BgNVBAcTB05ld2J1cnkxFzAVBgNVBAoTDk15IENvbXBhbnkgTHRkMRAwDgYDVQQL +EwdUZXN0aW5nMQ0wCwYDVQQDEwR0ZXN0MRwwGgYJKoZIhvcNAQkBFg10ZXN0QHRl +c3QuY29tggkA6+dk+3n3IhkwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOC +AQEAVRG4aALIvCXCiKfe7K+iJxjBVRDFPEf7JWA9LGgbFOn6pNvbxonrR+0BETdc +JV1ET4ct2xsE7QNFIkp9GKRC+6J32zCo8qtLCD5+v436r8TUG2/t2JRMkb9I2XVT +p7RJoot6M0Ltf8KNQUPYh756xmKZ4USfQUwc58MOSDGY8VWEXJOYij9Pf0e0c52t +qiCEjXH7uXiS8Pgq9TYm7AkWSOrglYhSa83x0f8mtT8Q15nBESIHZ6o8FAS2bBgn +B0BkrKRjtBUkuJG3vTox+bYINh2Gxi1JZHWSV1tN5z3hd4VFcKqanW5OgQwToBqp +3nniskIjbH0xjgZf/nVMyLnjxg== +-----END CERTIFICATE----- diff --git a/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/test_client.p12 b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/test_client.p12 new file mode 100644 index 00000000..edc2af75 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/network-scripts/test_client.p12 Binary files differdiff --git a/src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c new file mode 100644 index 00000000..59127d01 --- /dev/null +++ b/src/core/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -0,0 +1,11858 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2008 - 2011 Red Hat, Inc. + */ + +#include "src/core/nm-default-daemon.h" + +#include <stdio.h> +#include <stdarg.h> +#include <unistd.h> +#include <linux/pkt_sched.h> +#include <netinet/in.h> +#include <arpa/inet.h> +#include <sys/socket.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <linux/if_ether.h> +#include <linux/if_infiniband.h> + +#include "nm-glib-aux/nm-json-aux.h" +#include "nm-utils.h" +#include "nm-setting-connection.h" +#include "nm-setting-wired.h" +#include "nm-setting-user.h" +#include "nm-setting-wireless.h" +#include "nm-setting-wireless-security.h" +#include "nm-setting-ip4-config.h" +#include "nm-setting-ip6-config.h" +#include "nm-setting-8021x.h" +#include "nm-setting-pppoe.h" +#include "nm-setting-ppp.h" +#include "nm-setting-vpn.h" +#include "nm-setting-ethtool.h" +#include "nm-setting-gsm.h" +#include "nm-setting-cdma.h" +#include "nm-setting-serial.h" +#include "nm-setting-vlan.h" +#include "nm-setting-dcb.h" +#include "nm-core-internal.h" +#include "nm-base/nm-ethtool-base.h" +#include "nm-base/nm-ethtool-utils-base.h" + +#include "NetworkManagerUtils.h" + +#include "settings/plugins/ifcfg-rh/nms-ifcfg-rh-common.h" +#include "settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.h" +#include "settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.h" +#include "settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h" + +#include "nm-test-utils-core.h" + +#define TEST_IFCFG_DIR NM_BUILD_SRCDIR "/src/core/settings/plugins/ifcfg-rh/tests/network-scripts" +#define TEST_SCRATCH_DIR \ + NM_BUILD_BUILDDIR "/src/core/settings/plugins/ifcfg-rh/tests/network-scripts" +#define TEST_SCRATCH_DIR_TMP TEST_SCRATCH_DIR "/tmp" + +#define TEST_SCRATCH_ALIAS_BASE TEST_SCRATCH_DIR "/ifcfg-alias0" + +/*****************************************************************************/ + +#define _svOpenFile(testfile) \ + ({ \ + shvarFile * _f; \ + GError * _error = NULL; \ + const char *_testfile = (testfile); \ + \ + g_assert(_testfile); \ + _f = svOpenFile(_testfile, &_error); \ + nmtst_assert_success(_f, _error); \ + _f; \ + }) + +#define _svGetValue_check(f, key, expected_value) \ + G_STMT_START \ + { \ + const char * _val; \ + gs_free char * _to_free = NULL; \ + gs_free char * _val_string = NULL; \ + shvarFile *const _f = (f); \ + const char *const _key = (key); \ + \ + _val_string = svGetValueStr_cp(_f, _key); \ + _val = svGetValue(_f, _key, &_to_free); \ + g_assert_cmpstr(_val, ==, (expected_value)); \ + g_assert((!_val_string && (!_val || !_val[0])) \ + || (_val_string && nm_streq0(_val, _val_string))); \ + } \ + G_STMT_END + +static void +_assert_reread_same(NMConnection *connection, NMConnection *reread) +{ + nmtst_assert_connection_verifies_without_normalization(reread); + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +_assert_reread_same_FIXME(NMConnection *connection, NMConnection *reread) +{ + gs_unref_object NMConnection *connection_normalized = NULL; + gs_unref_hashtable GHashTable *settings = NULL; + + /* FIXME: these assertion failures should not happen as we expect + * that re-reading a connection after write yields the same result. + * + * Needs investigation and fixing. */ + nmtst_assert_connection_verifies_without_normalization(reread); + + connection_normalized = nmtst_connection_duplicate_and_normalize(connection); + + g_assert(!nm_connection_compare(connection_normalized, reread, NM_SETTING_COMPARE_FLAG_EXACT)); + g_assert(!nm_connection_diff(connection_normalized, + reread, + NM_SETTING_COMPARE_FLAG_EXACT, + &settings)); +} + +/* dummy path for an "expected" file, meaning: don't check for expected + * written ifcfg file. */ +static const char NO_EXPECTED[1]; + +static void +_assert_expected_content(NMConnection *connection, const char *filename, const char *expected) +{ + gs_free char *content_expectd = NULL; + gs_free char *content_written = NULL; + GError * error = NULL; + gsize len_expectd = 0; + gsize len_written = 0; + gboolean success; + const char * uuid = NULL; + + g_assert(NM_IS_CONNECTION(connection)); + g_assert(filename); + g_assert(g_file_test(filename, G_FILE_TEST_EXISTS)); + + g_assert(expected); + if (expected == NO_EXPECTED) + return; + + success = g_file_get_contents(filename, &content_written, &len_written, &error); + nmtst_assert_success(success, error); + + success = g_file_get_contents(expected, &content_expectd, &len_expectd, &error); + nmtst_assert_success(success, error); + + { + gsize i, j; + + for (i = 0; i < len_expectd;) { + if (content_expectd[i] != '$') { + i++; + continue; + } + if (g_str_has_prefix(&content_expectd[i], "${UUID}")) { + GString *str; + + if (!uuid) { + uuid = nm_connection_get_uuid(connection); + g_assert(uuid); + } + + j = strlen(uuid); + + str = g_string_new_len(content_expectd, len_expectd); + g_string_erase(str, i, NM_STRLEN("${UUID}")); + g_string_insert_len(str, i, uuid, j); + + g_free(content_expectd); + len_expectd = str->len; + content_expectd = g_string_free(str, FALSE); + i += j; + continue; + } + + /* other '$' is not supported. If need be, support escaping of + * '$' via '$$'. */ + g_assert_not_reached(); + } + } + + if (len_expectd != len_written || memcmp(content_expectd, content_written, len_expectd) != 0) { + if (g_getenv("NMTST_IFCFG_RH_UPDATE_EXPECTED") + || nm_streq0(g_getenv("NM_TEST_REGENERATE"), "1")) { + if (uuid) { + gs_free char *search = g_strdup_printf("UUID=%s\n", uuid); + const char * s; + gsize i; + GString * str; + + s = content_written; + while (TRUE) { + s = strstr(s, search); + g_assert(s); + if (s == content_written || s[-1] == '\n') + break; + s += strlen(search); + } + + i = s - content_written; + + str = g_string_new_len(content_written, len_written); + g_string_erase(str, i, strlen(search)); + g_string_insert(str, i, "UUID=${UUID}\n"); + + len_written = str->len; + content_written = g_string_free(str, FALSE); + } + success = g_file_set_contents(expected, content_written, len_written, &error); + nmtst_assert_success(success, error); + } else { + g_error("The content of \"%s\" (%zu) differs from \"%s\" (%zu). Set " + "NMTST_IFCFG_RH_UPDATE_EXPECTED=yes to update the files " + "inplace\n\n>>>%s<<<\n\n>>>%s<<<\n", + filename, + len_written, + expected, + len_expectd, + content_written, + content_expectd); + } + } +} + +#define _writer_update_connection_reread(connection, \ + ifcfg_dir, \ + filename, \ + expected, \ + out_reread, \ + out_reread_same) \ + G_STMT_START \ + { \ + gs_unref_object NMConnection *_connection = \ + nmtst_connection_duplicate_and_normalize(connection); \ + NMConnection **_out_reread = (out_reread); \ + gboolean * _out_reread_same = (out_reread_same); \ + const char * _ifcfg_dir = (ifcfg_dir); \ + const char * _filename = (filename); \ + const char * _expected = (expected); \ + GError * _error = NULL; \ + gboolean _success; \ + \ + g_assert(_ifcfg_dir &&_ifcfg_dir[0]); \ + g_assert(_filename &&_filename[0]); \ + \ + _success = nms_ifcfg_rh_writer_write_connection(_connection, \ + _ifcfg_dir, \ + _filename, \ + NULL, \ + NULL, \ + NULL, \ + _out_reread, \ + _out_reread_same, \ + &_error); \ + nmtst_assert_success(_success, _error); \ + _assert_expected_content(_connection, _filename, _expected); \ + } \ + G_STMT_END + +#define _writer_update_connection(connection, ifcfg_dir, filename, expected) \ + G_STMT_START \ + { \ + gs_unref_object NMConnection *_reread = NULL; \ + NMConnection * _c = (connection); \ + gboolean _reread_same = FALSE; \ + \ + _writer_update_connection_reread(_c, \ + ifcfg_dir, \ + filename, \ + expected, \ + &_reread, \ + &_reread_same); \ + _assert_reread_same(_c, _reread); \ + g_assert(_reread_same); \ + } \ + G_STMT_END + +static NMConnection * +_connection_from_file(const char *filename, + const char *network_file, + const char *test_type, + char ** out_unhandled) +{ + NMConnection *connection; + GError * error = NULL; + char * unhandled_fallback = NULL; + + g_assert(!out_unhandled || !*out_unhandled); + + connection = nmtst_connection_from_file(filename, + network_file, + test_type, + out_unhandled ?: &unhandled_fallback, + &error); + g_assert_no_error(error); + g_assert(!unhandled_fallback); + + if (out_unhandled && *out_unhandled) + nmtst_assert_connection_verifies(connection); + else + nmtst_assert_connection_verifies_without_normalization(connection); + return connection; +} + +static void +_connection_from_file_fail(const char *filename, + const char *network_file, + const char *test_type, + GError ** error) +{ + NMConnection *connection; + GError * local = NULL; + char * unhandled = NULL; + + connection = nmtst_connection_from_file(filename, network_file, test_type, &unhandled, &local); + + g_assert(!connection); + g_assert(local); + g_assert(!unhandled); + g_propagate_error(error, local); +} + +static void +_writer_new_connection_reread(NMConnection * connection, + const char * ifcfg_dir, + char ** out_filename, + const char * expected, + NMConnection **out_reread, + gboolean * out_reread_same) +{ + gboolean success; + GError * error = NULL; + char * filename = NULL; + gs_unref_object NMConnection *con_verified = NULL; + gs_unref_object NMConnection *reread_copy = NULL; + NMConnection **reread = out_reread ?: ((nmtst_get_rand_uint32() % 2) ? &reread_copy : NULL); + + g_assert(NM_IS_CONNECTION(connection)); + g_assert(ifcfg_dir); + + con_verified = nmtst_connection_duplicate_and_normalize(connection); + + success = nms_ifcfg_rh_writer_write_connection(con_verified, + ifcfg_dir, + NULL, + NULL, + NULL, + &filename, + reread, + out_reread_same, + &error); + nmtst_assert_success(success, error); + g_assert(filename && filename[0]); + + if (reread) + nmtst_assert_connection_verifies_without_normalization(*reread); + + _assert_expected_content(con_verified, filename, expected); + + if (out_filename) + *out_filename = filename; + else + g_free(filename); +} + +static void +_writer_new_connec_exp(NMConnection *connection, + const char * ifcfg_dir, + const char * expected, + char ** out_filename) +{ + gs_unref_object NMConnection *reread = NULL; + gboolean reread_same = FALSE; + + _writer_new_connection_reread(connection, + ifcfg_dir, + out_filename, + expected, + &reread, + &reread_same); + _assert_reread_same(connection, reread); + g_assert(reread_same); +} + +static void +_writer_new_connection(NMConnection *connection, const char *ifcfg_dir, char **out_filename) +{ + _writer_new_connec_exp(connection, ifcfg_dir, NO_EXPECTED, out_filename); +} + +static void +_writer_new_connection_FIXME(NMConnection *connection, const char *ifcfg_dir, char **out_filename) +{ + gs_unref_object NMConnection *reread = NULL; + gboolean reread_same = FALSE; + + /* FIXME: this should not happen. Fix it to use _writer_new_connection() instead. */ + + _writer_new_connection_reread(connection, + ifcfg_dir, + out_filename, + NO_EXPECTED, + &reread, + &reread_same); + _assert_reread_same_FIXME(connection, reread); + g_assert(!reread_same); +} + +static void +_writer_new_connection_fail(NMConnection *connection, const char *ifcfg_dir, GError **error) +{ + gs_unref_object NMConnection *connection_normalized = NULL; + gs_unref_object NMConnection *reread = NULL; + gboolean success; + GError * local = NULL; + char * filename = NULL; + + g_assert(NM_IS_CONNECTION(connection)); + g_assert(ifcfg_dir); + + connection_normalized = nmtst_connection_duplicate_and_normalize(connection); + + success = nms_ifcfg_rh_writer_write_connection(connection_normalized, + ifcfg_dir, + NULL, + NULL, + NULL, + &filename, + &reread, + NULL, + &local); + nmtst_assert_no_success(success, local); + g_assert(!filename); + g_assert(!reread); + + g_propagate_error(error, local); +} + +/*****************************************************************************/ + +static void +test_read_netmask_1(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_free char * content = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + NMIPAddress * ip4_addr; + const char * FILENAME = TEST_IFCFG_DIR "/ifcfg-netmask-1"; + + connection = _connection_from_file(FILENAME, NULL, TYPE_ETHERNET, NULL); + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System netmask-1"); + + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + g_assert_cmpuint(nm_setting_ip_config_get_num_dns(s_ip4), ==, 1); + ip4_addr = nm_setting_ip_config_get_address(s_ip4, 0); + g_assert(ip4_addr); + g_assert_cmpstr(nm_ip_address_get_address(ip4_addr), ==, "102.0.2.2"); + g_assert_cmpint(nm_ip_address_get_prefix(ip4_addr), ==, 15); + + nmtst_assert_connection_verifies_without_normalization(connection); + + content = nmtst_file_get_contents(FILENAME); + + testfile = g_strdup(TEST_SCRATCH_DIR "/ifcfg-netmask-1.copy"); + + nmtst_file_set_contents(testfile, content); + + _writer_update_connection(connection, + TEST_SCRATCH_DIR, + testfile, + TEST_IFCFG_DIR "/ifcfg-netmask-1.cexpected"); +} + +/*****************************************************************************/ + +static gboolean +verify_cert_or_key(NMSetting8021x *s_compare, + const char * file, + const char * privkey_password, + const char * property) +{ + NMSetting8021x * s_8021x; + GError * error = NULL; + gboolean success = FALSE; + const char * expected = NULL, *setting = NULL; + gboolean phase2 = FALSE; + NMSetting8021xCKScheme scheme = NM_SETTING_802_1X_CK_SCHEME_UNKNOWN; + + if (strstr(property, "phase2")) + phase2 = TRUE; + + s_8021x = (NMSetting8021x *) nm_setting_802_1x_new(); + + /* Load the certificate into an empty setting */ + if (strstr(property, "ca-cert")) { + if (phase2) + success = nm_setting_802_1x_set_phase2_ca_cert(s_8021x, + file, + NM_SETTING_802_1X_CK_SCHEME_PATH, + NULL, + &error); + else + success = nm_setting_802_1x_set_ca_cert(s_8021x, + file, + NM_SETTING_802_1X_CK_SCHEME_PATH, + NULL, + &error); + } else if (strstr(property, "client-cert")) { + if (phase2) + success = nm_setting_802_1x_set_phase2_client_cert(s_8021x, + file, + NM_SETTING_802_1X_CK_SCHEME_PATH, + NULL, + &error); + else + success = nm_setting_802_1x_set_client_cert(s_8021x, + file, + NM_SETTING_802_1X_CK_SCHEME_PATH, + NULL, + &error); + } else if (strstr(property, "private-key")) { + if (phase2) + success = nm_setting_802_1x_set_phase2_private_key(s_8021x, + file, + privkey_password, + NM_SETTING_802_1X_CK_SCHEME_PATH, + NULL, + &error); + else + success = nm_setting_802_1x_set_private_key(s_8021x, + file, + privkey_password, + NM_SETTING_802_1X_CK_SCHEME_PATH, + NULL, + &error); + } + g_assert_no_error(error); + g_assert_cmpint(success, ==, TRUE); + + /* Ensure it was loaded using the PATH scheme */ + if (strstr(property, "ca-cert")) { + if (phase2) + scheme = nm_setting_802_1x_get_phase2_ca_cert_scheme(s_8021x); + else + scheme = nm_setting_802_1x_get_ca_cert_scheme(s_8021x); + } else if (strstr(property, "client-cert")) { + if (phase2) + scheme = nm_setting_802_1x_get_phase2_client_cert_scheme(s_8021x); + else + scheme = nm_setting_802_1x_get_client_cert_scheme(s_8021x); + } else if (strstr(property, "private-key")) { + if (phase2) + scheme = nm_setting_802_1x_get_phase2_private_key_scheme(s_8021x); + else + scheme = nm_setting_802_1x_get_private_key_scheme(s_8021x); + } + g_assert_cmpint(scheme, ==, NM_SETTING_802_1X_CK_SCHEME_PATH); + + /* Grab the path back out */ + if (strstr(property, "ca-cert")) { + if (phase2) + expected = nm_setting_802_1x_get_phase2_ca_cert_path(s_8021x); + else + expected = nm_setting_802_1x_get_ca_cert_path(s_8021x); + } else if (strstr(property, "client-cert")) { + if (phase2) + expected = nm_setting_802_1x_get_phase2_client_cert_path(s_8021x); + else + expected = nm_setting_802_1x_get_client_cert_path(s_8021x); + } else if (strstr(property, "private-key")) { + if (phase2) + expected = nm_setting_802_1x_get_phase2_private_key_path(s_8021x); + else + expected = nm_setting_802_1x_get_private_key_path(s_8021x); + } + g_assert_cmpstr(expected, ==, file); + + /* Compare the path with the expected path from the real setting */ + if (strstr(property, "ca-cert")) { + if (phase2) + setting = nm_setting_802_1x_get_phase2_ca_cert_path(s_compare); + else + setting = nm_setting_802_1x_get_ca_cert_path(s_compare); + } else if (strstr(property, "client-cert")) { + if (phase2) + setting = nm_setting_802_1x_get_phase2_client_cert_path(s_compare); + else + setting = nm_setting_802_1x_get_client_cert_path(s_compare); + } else if (strstr(property, "private-key")) { + if (phase2) + setting = nm_setting_802_1x_get_phase2_private_key_path(s_compare); + else + setting = nm_setting_802_1x_get_private_key_path(s_compare); + } + g_assert_cmpstr(setting, ==, expected); + + g_object_unref(s_8021x); + return TRUE; +} + +static void +test_read_basic(void) +{ + NMConnection * connection; + NMSettingConnection *s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + const char * mac; + char expected_mac_address[ETH_ALEN] = {0x00, 0x16, 0x41, 0x11, 0x22, 0x33}; + + connection = + _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-minimal", NULL, TYPE_ETHERNET, NULL); + + /* ===== CONNECTION SETTING ===== */ + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-minimal"); + g_assert_cmpint(nm_setting_connection_get_timestamp(s_con), ==, 0); + g_assert(nm_setting_connection_get_autoconnect(s_con)); + g_assert_cmpint(nm_setting_connection_get_autoconnect_retries(s_con), ==, -1); + + /* UUID can't be tested if the ifcfg does not contain the UUID key, because + * the UUID is generated on the full path of the ifcfg file, which can change + * depending on where the tests are run. + */ + + /* ===== WIRED SETTING ===== */ + s_wired = nm_connection_get_setting_wired(connection); + g_assert(s_wired); + g_assert_cmpint(nm_setting_wired_get_mtu(s_wired), ==, 0); + + /* MAC address */ + mac = nm_setting_wired_get_mac_address(s_wired); + g_assert(mac); + g_assert(nm_utils_hwaddr_matches(mac, -1, expected_mac_address, ETH_ALEN)); + + /* ===== IPv4 SETTING ===== */ + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), + ==, + NM_SETTING_IP4_CONFIG_METHOD_DISABLED); + g_assert(nm_setting_ip_config_get_never_default(s_ip4) == FALSE); + + /* ===== IPv6 SETTING ===== */ + s_ip6 = nm_connection_get_setting_ip6_config(connection); + g_assert(s_ip6); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip6), + ==, + NM_SETTING_IP6_CONFIG_METHOD_IGNORE); + g_assert(nm_setting_ip_config_get_never_default(s_ip6) == FALSE); + + g_object_unref(connection); +} + +static void +test_read_miscellaneous_variables(void) +{ + NMConnection * connection; + NMSettingConnection *s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + char * expected_mac_blacklist[3] = {"00:16:41:11:22:88", + "00:16:41:11:22:99", + "6a:5d:5a:fa:dd:f0"}; + int mac_blacklist_num, i; + guint64 expected_timestamp = 0; + + NMTST_EXPECT_NM_WARN("*invalid MAC in HWADDR_BLACKLIST 'XX:aa:invalid'*"); + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-misc-variables", + NULL, + TYPE_ETHERNET, + NULL); + g_test_assert_expected_messages(); + + /* ===== CONNECTION SETTING ===== */ + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpint(nm_setting_connection_get_timestamp(s_con), ==, expected_timestamp); + g_assert(nm_setting_connection_get_autoconnect(s_con)); + g_assert_cmpint(nm_setting_connection_get_autoconnect_retries(s_con), ==, 100); + + /* ===== WIRED SETTING ===== */ + s_wired = nm_connection_get_setting_wired(connection); + g_assert(s_wired); + g_assert_cmpint(nm_setting_wired_get_mtu(s_wired), ==, 0); + + /* MAC blacklist */ + mac_blacklist_num = nm_setting_wired_get_num_mac_blacklist_items(s_wired); + g_assert_cmpint(mac_blacklist_num, ==, 3); + for (i = 0; i < mac_blacklist_num; i++) + g_assert(nm_utils_hwaddr_matches(nm_setting_wired_get_mac_blacklist_item(s_wired, i), + -1, + expected_mac_blacklist[i], + -1)); + + /* ===== IPv4 SETTING ===== */ + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), + ==, + NM_SETTING_IP4_CONFIG_METHOD_DISABLED); + g_assert(nm_setting_ip_config_get_never_default(s_ip4) == FALSE); + + g_object_unref(connection); +} + +static void +test_read_variables_corner_cases(void) +{ + NMConnection * connection; + NMSettingConnection *s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + const char * mac; + char expected_mac_address[ETH_ALEN] = {0x00, 0x16, 0x41, 0x11, 0x22, 0x33}; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-variables-corner-cases-1", + NULL, + TYPE_ETHERNET, + NULL); + + /* ===== CONNECTION SETTING ===== */ + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), + ==, + "System test-variables-corner-cases-1"); + g_assert_cmpstr(nm_setting_connection_get_zone(s_con), ==, NULL); + g_assert_cmpint(nm_setting_connection_get_timestamp(s_con), ==, 0); + g_assert(nm_setting_connection_get_autoconnect(s_con)); + + /* ===== WIRED SETTING ===== */ + s_wired = nm_connection_get_setting_wired(connection); + g_assert(s_wired); + g_assert_cmpint(nm_setting_wired_get_mtu(s_wired), ==, 0); + + /* MAC address */ + mac = nm_setting_wired_get_mac_address(s_wired); + g_assert(mac); + g_assert(nm_utils_hwaddr_matches(mac, -1, expected_mac_address, ETH_ALEN)); + + /* ===== IPv4 SETTING ===== */ + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), + ==, + NM_SETTING_IP4_CONFIG_METHOD_DISABLED); + g_assert(nm_setting_ip_config_get_never_default(s_ip4) == FALSE); + + g_object_unref(connection); +} + +static void +test_read_unmanaged(void) +{ + NMConnection * connection; + NMSettingConnection *s_con; + char * unhandled_spec = NULL; + guint64 expected_timestamp = 0; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-nm-controlled", + NULL, + TYPE_ETHERNET, + &unhandled_spec); + g_assert_cmpstr(unhandled_spec, ==, "unmanaged:mac:00:11:22:33:f8:9f"); + + /* ===== CONNECTION SETTING ===== */ + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-nm-controlled"); + g_assert_cmpint(nm_setting_connection_get_timestamp(s_con), ==, expected_timestamp); + g_assert(nm_setting_connection_get_autoconnect(s_con)); + + g_free(unhandled_spec); + g_object_unref(connection); +} + +static void +test_read_unmanaged_unrecognized(void) +{ + NMConnection * connection; + NMSettingConnection *s_con; + gs_free char * unhandled_spec = NULL; + guint64 expected_timestamp = 0; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-nm-controlled-unrecognized", + NULL, + NULL, + &unhandled_spec); + g_assert_cmpstr(unhandled_spec, ==, "unmanaged:interface-name:=ipoac0"); + + /* ===== CONNECTION SETTING ===== */ + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "PigeonNet"); + g_assert_cmpint(nm_setting_connection_get_timestamp(s_con), ==, expected_timestamp); + + g_object_unref(connection); +} + +static void +test_read_unrecognized(void) +{ + NMConnection * connection; + NMSettingConnection *s_con; + gs_free char * unhandled_spec = NULL; + guint64 expected_timestamp = 0; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-unrecognized", + NULL, + NULL, + &unhandled_spec); + g_assert_cmpstr(unhandled_spec, ==, "unrecognized:mac:00:11:22:33"); + + /* ===== CONNECTION SETTING ===== */ + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-unrecognized"); + g_assert_cmpint(nm_setting_connection_get_timestamp(s_con), ==, expected_timestamp); + + g_object_unref(connection); +} + +static void +test_read_wired_static(gconstpointer test_data) +{ + NMConnection * connection; + NMSettingConnection *s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + char * unmanaged = NULL; + const char * mac; + char expected_mac_address[ETH_ALEN] = {0x00, 0x11, 0x22, 0x33, 0x44, 0xee}; + NMIPAddress * ip4_addr; + NMIPAddress * ip6_addr; + const char * file, *expected_id; + gpointer expect_ip6_p; + + nmtst_test_data_unpack(test_data, &file, &expected_id, &expect_ip6_p); + + g_assert(expected_id); + + connection = _connection_from_file(file, NULL, TYPE_ETHERNET, &unmanaged); + g_assert_cmpstr(unmanaged, ==, NULL); + + /* ===== CONNECTION SETTING ===== */ + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, expected_id); + g_assert_cmpint(nm_setting_connection_get_timestamp(s_con), ==, 0); + g_assert(nm_setting_connection_get_autoconnect(s_con)); + + /* ===== WIRED SETTING ===== */ + s_wired = nm_connection_get_setting_wired(connection); + g_assert(s_wired); + g_assert_cmpint(nm_setting_wired_get_mtu(s_wired), ==, 1492); + + /* MAC address */ + mac = nm_setting_wired_get_mac_address(s_wired); + g_assert(mac); + g_assert(nm_utils_hwaddr_matches(mac, -1, expected_mac_address, ETH_ALEN)); + + /* ===== IPv4 SETTING ===== */ + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), + ==, + NM_SETTING_IP4_CONFIG_METHOD_MANUAL); + g_assert(nm_setting_ip_config_get_may_fail(s_ip4)); + + g_assert(nm_setting_ip_config_has_dns_options(s_ip4)); + g_assert_cmpint(nm_setting_ip_config_get_num_dns_options(s_ip4), ==, 0); + + /* DNS Addresses */ + g_assert_cmpint(nm_setting_ip_config_get_num_dns(s_ip4), ==, 2); + g_assert_cmpstr(nm_setting_ip_config_get_dns(s_ip4, 0), ==, "4.2.2.1"); + g_assert_cmpstr(nm_setting_ip_config_get_dns(s_ip4, 1), ==, "4.2.2.2"); + + /* IP addresses */ + g_assert_cmpint(nm_setting_ip_config_get_num_addresses(s_ip4), ==, 1); + ip4_addr = nm_setting_ip_config_get_address(s_ip4, 0); + g_assert(ip4_addr); + g_assert_cmpint(nm_ip_address_get_prefix(ip4_addr), ==, 24); + g_assert_cmpstr(nm_ip_address_get_address(ip4_addr), ==, "192.168.1.5"); + + /* Gateway */ + g_assert_cmpstr(nm_setting_ip_config_get_gateway(s_ip4), ==, "192.168.1.1"); + + /* ===== IPv6 SETTING ===== */ + s_ip6 = nm_connection_get_setting_ip6_config(connection); + g_assert(s_ip6); + if (GPOINTER_TO_INT(expect_ip6_p)) { + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip6), + ==, + NM_SETTING_IP6_CONFIG_METHOD_MANUAL); + g_assert(nm_setting_ip_config_get_may_fail(s_ip6)); + + g_assert(nm_setting_ip_config_has_dns_options(s_ip6)); + g_assert_cmpint(nm_setting_ip_config_get_num_dns_options(s_ip6), ==, 0); + + /* DNS Addresses */ + g_assert_cmpint(nm_setting_ip_config_get_num_dns(s_ip6), ==, 2); + g_assert_cmpstr(nm_setting_ip_config_get_dns(s_ip6, 0), ==, "1:2:3:4::a"); + g_assert_cmpstr(nm_setting_ip_config_get_dns(s_ip6, 1), ==, "1:2:3:4::b"); + + /* IP addresses */ + g_assert_cmpint(nm_setting_ip_config_get_num_addresses(s_ip6), ==, 2); + + ip6_addr = nm_setting_ip_config_get_address(s_ip6, 0); + g_assert(ip6_addr); + g_assert_cmpint(nm_ip_address_get_prefix(ip6_addr), ==, 64); + g_assert_cmpstr(nm_ip_address_get_address(ip6_addr), ==, "dead:beaf::1"); + + ip6_addr = nm_setting_ip_config_get_address(s_ip6, 1); + g_assert(ip6_addr); + g_assert_cmpint(nm_ip_address_get_prefix(ip6_addr), ==, 56); + g_assert_cmpstr(nm_ip_address_get_address(ip6_addr), ==, "dead:beaf::2"); + } else { + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip6), + ==, + NM_SETTING_IP6_CONFIG_METHOD_IGNORE); + g_assert(!nm_setting_ip_config_has_dns_options(s_ip6)); + } + + g_object_unref(connection); +} + +static void +test_read_wired_static_no_prefix(gconstpointer user_data) +{ + guint32 expected_prefix = GPOINTER_TO_UINT(user_data); + NMConnection * connection; + NMSettingConnection *s_con; + NMSettingIPConfig * s_ip4; + NMIPAddress * ip4_addr; + char * file, *expected_id; + + file = g_strdup_printf(TEST_IFCFG_DIR "/ifcfg-test-wired-static-no-prefix-%u", expected_prefix); + expected_id = g_strdup_printf("System test-wired-static-no-prefix-%u", expected_prefix); + + NMTST_EXPECT_NM_WARN("*missing PREFIX, assuming*"); + connection = _connection_from_file(file, NULL, TYPE_ETHERNET, NULL); + g_test_assert_expected_messages(); + + /* ===== CONNECTION SETTING ===== */ + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, expected_id); + + /* ===== IPv4 SETTING ===== */ + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), + ==, + NM_SETTING_IP4_CONFIG_METHOD_MANUAL); + + g_assert(!nm_setting_ip_config_has_dns_options(s_ip4)); + g_assert_cmpint(nm_setting_ip_config_get_num_dns_options(s_ip4), ==, 0); + + g_assert_cmpint(nm_setting_ip_config_get_num_addresses(s_ip4), ==, 1); + ip4_addr = nm_setting_ip_config_get_address(s_ip4, 0); + g_assert(ip4_addr); + g_assert_cmpint(nm_ip_address_get_prefix(ip4_addr), ==, expected_prefix); + + g_free(file); + g_free(expected_id); + g_object_unref(connection); +} + +static void +test_read_wired_dhcp(void) +{ + NMConnection * connection; + NMSettingConnection *s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + char * unmanaged = NULL; + char expected_mac_address[ETH_ALEN] = {0x00, 0x11, 0x22, 0x33, 0x44, 0xee}; + const char * mac; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-dhcp", + NULL, + TYPE_ETHERNET, + &unmanaged); + g_assert(unmanaged == NULL); + + /* ===== CONNECTION SETTING ===== */ + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-wired-dhcp"); + g_assert_cmpuint(nm_setting_connection_get_timestamp(s_con), ==, 0); + g_assert(nm_setting_connection_get_autoconnect(s_con)); + + /* ===== WIRED SETTING ===== */ + s_wired = nm_connection_get_setting_wired(connection); + g_assert(s_wired); + + /* MAC address */ + mac = nm_setting_wired_get_mac_address(s_wired); + g_assert(mac); + g_assert(nm_utils_hwaddr_matches(mac, -1, expected_mac_address, sizeof(expected_mac_address))); + + /* ===== IPv4 SETTING ===== */ + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); + g_assert_cmpstr(nm_setting_ip4_config_get_dhcp_fqdn(NM_SETTING_IP4_CONFIG(s_ip4)), + ==, + "foo.bar"); + g_assert(nm_setting_ip_config_get_ignore_auto_dns(s_ip4)); + g_assert_cmpuint(nm_setting_ip_config_get_num_dns(s_ip4), ==, 2); + g_assert_cmpstr(nm_setting_ip_config_get_dns(s_ip4, 0), ==, "4.2.2.1"); + g_assert_cmpstr(nm_setting_ip_config_get_dns(s_ip4, 1), ==, "4.2.2.2"); + g_assert_cmpuint(nm_setting_ip_config_get_dhcp_hostname_flags(s_ip4), + ==, + NM_DHCP_HOSTNAME_FLAG_FQDN_ENCODED | NM_DHCP_HOSTNAME_FLAG_FQDN_NO_UPDATE); + + /* ===== IPv6 SETTING ===== */ + s_ip6 = nm_connection_get_setting_ip6_config(connection); + g_assert(s_ip6); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_DHCP); + g_assert_cmpstr(nm_setting_ip_config_get_dhcp_hostname(s_ip6), ==, "foo.bar"); + g_assert_cmpuint(nm_setting_ip_config_get_dhcp_hostname_flags(s_ip6), + ==, + NM_DHCP_HOSTNAME_FLAG_FQDN_CLEAR_FLAGS); + + g_object_unref(connection); +} + +static void +test_read_wired_dhcp_plus_ip(void) +{ + NMConnection * connection; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + NMIPAddress * ip4_addr; + NMIPAddress * ip6_addr; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-dhcp-plus-ip", + NULL, + TYPE_ETHERNET, + NULL); + + /* ===== IPv4 SETTING ===== */ + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); + g_assert(nm_setting_ip_config_get_may_fail(s_ip4)); + + /* DNS Addresses */ + g_assert_cmpint(nm_setting_ip_config_get_num_dns(s_ip4), ==, 2); + g_assert_cmpstr(nm_setting_ip_config_get_dns(s_ip4, 0), ==, "4.2.2.1"); + g_assert_cmpstr(nm_setting_ip_config_get_dns(s_ip4, 1), ==, "4.2.2.2"); + + /* IP addresses */ + g_assert_cmpint(nm_setting_ip_config_get_num_addresses(s_ip4), ==, 2); + ip4_addr = nm_setting_ip_config_get_address(s_ip4, 0); + g_assert(ip4_addr); + g_assert_cmpint(nm_ip_address_get_prefix(ip4_addr), ==, 24); + g_assert_cmpstr(nm_ip_address_get_address(ip4_addr), ==, "1.2.3.4"); + + /* Gateway */ + g_assert_cmpstr(nm_setting_ip_config_get_gateway(s_ip4), ==, "1.1.1.1"); + + ip4_addr = nm_setting_ip_config_get_address(s_ip4, 1); + g_assert(ip4_addr); + g_assert_cmpint(nm_ip_address_get_prefix(ip4_addr), ==, 16); + g_assert_cmpstr(nm_ip_address_get_address(ip4_addr), ==, "9.8.7.6"); + + /* ===== IPv6 SETTING ===== */ + s_ip6 = nm_connection_get_setting_ip6_config(connection); + g_assert(s_ip6); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_AUTO); + g_assert(nm_setting_ip_config_get_may_fail(s_ip6)); + + /* DNS Addresses */ + g_assert_cmpint(nm_setting_ip_config_get_num_dns(s_ip6), ==, 2); + g_assert_cmpstr(nm_setting_ip_config_get_dns(s_ip6, 0), ==, "1:2:3:4::a"); + g_assert_cmpstr(nm_setting_ip_config_get_dns(s_ip6, 1), ==, "1:2:3:4::b"); + + /* IP addresses */ + g_assert_cmpint(nm_setting_ip_config_get_num_addresses(s_ip6), ==, 3); + ip6_addr = nm_setting_ip_config_get_address(s_ip6, 0); + g_assert(ip6_addr); + g_assert_cmpint(nm_ip_address_get_prefix(ip6_addr), ==, 56); + g_assert_cmpstr(nm_ip_address_get_address(ip6_addr), ==, "1001:abba::1234"); + + ip6_addr = nm_setting_ip_config_get_address(s_ip6, 1); + g_assert(ip6_addr); + g_assert_cmpint(nm_ip_address_get_prefix(ip6_addr), ==, 64); + g_assert_cmpstr(nm_ip_address_get_address(ip6_addr), ==, "2001:abba::2234"); + + ip6_addr = nm_setting_ip_config_get_address(s_ip6, 2); + g_assert(ip6_addr); + g_assert_cmpint(nm_ip_address_get_prefix(ip6_addr), ==, 96); + g_assert_cmpstr(nm_ip_address_get_address(ip6_addr), ==, "3001:abba::3234"); + + g_object_unref(connection); +} + +static void +test_read_wired_shared_plus_ip(void) +{ + NMConnection * connection; + NMSettingIPConfig *s_ip4; + NMIPAddress * ip4_addr; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-shared-plus-ip", + NULL, + TYPE_ETHERNET, + NULL); + + /* ===== IPv4 SETTING ===== */ + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), + ==, + NM_SETTING_IP4_CONFIG_METHOD_SHARED); + g_assert(nm_setting_ip_config_get_may_fail(s_ip4)); + + /* IP addresses */ + g_assert_cmpint(nm_setting_ip_config_get_num_addresses(s_ip4), ==, 1); + ip4_addr = nm_setting_ip_config_get_address(s_ip4, 0); + g_assert(ip4_addr); + g_assert_cmpint(nm_ip_address_get_prefix(ip4_addr), ==, 24); + g_assert_cmpstr(nm_ip_address_get_address(ip4_addr), ==, "10.20.30.5"); + + /* Gateway */ + g_assert_cmpstr(nm_setting_ip_config_get_gateway(s_ip4), ==, "1.1.1.1"); + + g_object_unref(connection); +} + +static void +test_read_wired_global_gateway(void) +{ + NMConnection * connection; + NMSettingConnection *s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + NMIPAddress * ip4_addr; + char * unmanaged = NULL; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-global-gateway", + TEST_IFCFG_DIR "/network-test-wired-global-gateway", + TYPE_ETHERNET, + &unmanaged); + g_assert(unmanaged == NULL); + + /* ===== CONNECTION SETTING ===== */ + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-wired-global-gateway"); + + /* ===== WIRED SETTING ===== */ + s_wired = nm_connection_get_setting_wired(connection); + g_assert(s_wired); + + /* ===== IPv4 SETTING ===== */ + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), + ==, + NM_SETTING_IP4_CONFIG_METHOD_MANUAL); + + /* Address #1 */ + ip4_addr = nm_setting_ip_config_get_address(s_ip4, 0); + g_assert(ip4_addr); + g_assert_cmpint(nm_ip_address_get_prefix(ip4_addr), ==, 24); + g_assert_cmpstr(nm_ip_address_get_address(ip4_addr), ==, "192.168.1.5"); + + /* Gateway */ + g_assert_cmpstr(nm_setting_ip_config_get_gateway(s_ip4), ==, "192.168.1.2"); + + g_object_unref(connection); +} + +/* Ignore GATEWAY from /etc/sysconfig/network for automatic connections */ +static void +test_read_wired_global_gateway_ignore(void) +{ + NMConnection * connection; + NMSettingConnection *s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + char * unmanaged = NULL; + + NMTST_EXPECT_NM_WARN("*ignoring GATEWAY (/etc/sysconfig/network) for * because the connection " + "has no static addresses"); + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-global-gateway-ignore", + TEST_IFCFG_DIR "/network-test-wired-global-gateway-ignore", + TYPE_ETHERNET, + &unmanaged); + g_test_assert_expected_messages(); + g_assert(unmanaged == NULL); + + /* ===== CONNECTION SETTING ===== */ + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), + ==, + "System test-wired-global-gateway-ignore"); + + /* ===== WIRED SETTING ===== */ + s_wired = nm_connection_get_setting_wired(connection); + g_assert(s_wired); + + /* ===== IPv4 SETTING ===== */ + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); + + /* Addresses */ + g_assert_cmpint(nm_setting_ip_config_get_num_addresses(s_ip4), ==, 0); + + /* Gateway */ + g_assert_cmpstr(nm_setting_ip_config_get_gateway(s_ip4), ==, NULL); + + g_object_unref(connection); +} + +static void +test_read_wired_obsolete_gateway_n(void) +{ + NMConnection * connection; + NMSettingIPConfig *s_ip4; + NMIPAddress * ip4_addr; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-obsolete-gateway-n", + NULL, + TYPE_ETHERNET, + NULL); + + /* ===== IPv4 SETTING ===== */ + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), + ==, + NM_SETTING_IP4_CONFIG_METHOD_MANUAL); + + /* IP addresses */ + g_assert_cmpint(nm_setting_ip_config_get_num_addresses(s_ip4), ==, 1); + ip4_addr = nm_setting_ip_config_get_address(s_ip4, 0); + g_assert(ip4_addr); + g_assert_cmpint(nm_ip_address_get_prefix(ip4_addr), ==, 24); + g_assert_cmpstr(nm_ip_address_get_address(ip4_addr), ==, "1.2.3.4"); + + /* Gateway */ + g_assert_cmpstr(nm_setting_ip_config_get_gateway(s_ip4), ==, "1.1.1.1"); + + g_object_unref(connection); +} + +static void +test_user_1(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingUser * s_user; + + connection = + nmtst_create_minimal_connection("Test User 1", NULL, NM_SETTING_WIRED_SETTING_NAME, NULL); + s_user = NM_SETTING_USER(nm_setting_user_new()); + +#define _USER_SET_DATA(s_user, key, val) \ + G_STMT_START \ + { \ + GError * _error = NULL; \ + gboolean _success; \ + \ + _success = nm_setting_user_set_data((s_user), (key), (val), &_error); \ + nmtst_assert_success(_success, _error); \ + } \ + G_STMT_END + +#define _USER_SET_DATA_X(s_user, key) _USER_SET_DATA(s_user, key, "val=" key "") + + _USER_SET_DATA(s_user, "my.val1", ""); + _USER_SET_DATA_X(s_user, "my.val2"); + _USER_SET_DATA_X(s_user, "my.v__al3"); + _USER_SET_DATA_X(s_user, "my._v"); + _USER_SET_DATA_X(s_user, "my.v+"); + _USER_SET_DATA_X(s_user, "my.Av"); + _USER_SET_DATA_X(s_user, "MY.AV"); + _USER_SET_DATA_X(s_user, "MY.8V"); + _USER_SET_DATA_X(s_user, "MY.8-V"); + _USER_SET_DATA_X(s_user, "MY.8_V"); + _USER_SET_DATA_X(s_user, "MY.8+V"); + _USER_SET_DATA_X(s_user, "MY.8/V"); + _USER_SET_DATA_X(s_user, "MY.8=V"); + _USER_SET_DATA_X(s_user, "MY.-"); + _USER_SET_DATA_X(s_user, "MY._"); + _USER_SET_DATA_X(s_user, "MY.+"); + _USER_SET_DATA_X(s_user, "MY./"); + _USER_SET_DATA_X(s_user, "MY.="); + _USER_SET_DATA_X(s_user, "my.keys.1"); + _USER_SET_DATA_X(s_user, "my.other.KEY.42"); + + nm_connection_add_setting(connection, NM_SETTING(s_user)); + + _writer_new_connec_exp(connection, + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR "/ifcfg-Test_User_1.cexpected", + &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_read_wired_never_default(void) +{ + NMConnection * connection; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-never-default", + TEST_IFCFG_DIR "/network-test-wired-never-default", + TYPE_ETHERNET, + NULL); + + /* ===== WIRED SETTING ===== */ + g_assert(nm_connection_get_setting_wired(connection)); + + /* ===== IPv4 SETTING ===== */ + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); + g_assert(nm_setting_ip_config_get_never_default(s_ip4)); + g_assert_cmpint(nm_setting_ip_config_get_num_dns(s_ip4), ==, 0); + + /* ===== IPv6 SETTING ===== */ + s_ip6 = nm_connection_get_setting_ip6_config(connection); + g_assert(s_ip6); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_AUTO); + g_assert(nm_setting_ip_config_get_never_default(s_ip6)); + + g_object_unref(connection); +} + +static void +test_read_wired_defroute_no(void) +{ + NMConnection * connection; + NMSettingConnection *s_con; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + char * unmanaged = NULL; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-defroute-no", + NULL, + TYPE_ETHERNET, + &unmanaged); + g_assert(unmanaged == NULL); + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-wired-defroute-no"); + + g_assert(nm_connection_get_setting_wired(connection)); + + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); + g_assert(nm_setting_ip_config_get_never_default(s_ip4)); + + s_ip6 = nm_connection_get_setting_ip6_config(connection); + g_assert(s_ip6); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_AUTO); + g_assert(nm_setting_ip_config_get_never_default(s_ip6)); + + g_object_unref(connection); +} + +static void +test_read_wired_defroute_no_gatewaydev_yes(void) +{ + NMConnection * connection; + NMSettingConnection *s_con; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + char * unmanaged = NULL; + + connection = + _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-defroute-no-gatewaydev-yes", + TEST_IFCFG_DIR "/network-test-wired-defroute-no-gatewaydev-yes", + TYPE_ETHERNET, + &unmanaged); + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), + ==, + "System test-wired-defroute-no-gatewaydev-yes"); + + g_assert(nm_connection_get_setting_wired(connection)); + + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); + g_assert(nm_setting_ip_config_get_never_default(s_ip4) == FALSE); + + s_ip6 = nm_connection_get_setting_ip6_config(connection); + g_assert(s_ip6); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_AUTO); + g_assert(nm_setting_ip_config_get_never_default(s_ip6) == FALSE); + + g_object_unref(connection); +} + +static void +test_read_wired_static_routes(void) +{ + NMConnection * connection; + NMSettingConnection *s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + NMIPRoute * ip4_route; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-static-routes", + NULL, + TYPE_ETHERNET, + NULL); + + /* ===== CONNECTION SETTING ===== */ + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-wired-static-routes"); + + /* ===== WIRED SETTING ===== */ + s_wired = nm_connection_get_setting_wired(connection); + g_assert(s_wired); + + /* ===== IPv4 SETTING ===== */ + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), + ==, + NM_SETTING_IP4_CONFIG_METHOD_MANUAL); + + /* Routes */ + g_assert_cmpint(nm_setting_ip_config_get_num_routes(s_ip4), ==, 4); + + ip4_route = nm_setting_ip_config_get_route(s_ip4, 0); + g_assert(ip4_route); + g_assert_cmpstr(nm_ip_route_get_dest(ip4_route), ==, "11.22.33.0"); + g_assert_cmpint(nm_ip_route_get_prefix(ip4_route), ==, 24); + g_assert_cmpstr(nm_ip_route_get_next_hop(ip4_route), ==, "192.168.1.5"); + g_assert_cmpint(nm_ip_route_get_metric(ip4_route), ==, -1); + + ip4_route = nm_setting_ip_config_get_route(s_ip4, 1); + g_assert(ip4_route); + g_assert_cmpstr(nm_ip_route_get_dest(ip4_route), ==, "44.55.66.77"); + g_assert_cmpint(nm_ip_route_get_prefix(ip4_route), ==, 32); + g_assert_cmpstr(nm_ip_route_get_next_hop(ip4_route), ==, "192.168.1.7"); + g_assert_cmpint(nm_ip_route_get_metric(ip4_route), ==, 3); + nmtst_assert_route_attribute_byte(ip4_route, NM_IP_ROUTE_ATTRIBUTE_TOS, 0x28); + nmtst_assert_route_attribute_uint32(ip4_route, NM_IP_ROUTE_ATTRIBUTE_WINDOW, 30000); + nmtst_assert_route_attribute_uint32(ip4_route, NM_IP_ROUTE_ATTRIBUTE_CWND, 12); + nmtst_assert_route_attribute_uint32(ip4_route, NM_IP_ROUTE_ATTRIBUTE_INITCWND, 13); + nmtst_assert_route_attribute_uint32(ip4_route, NM_IP_ROUTE_ATTRIBUTE_INITRWND, 14); + nmtst_assert_route_attribute_uint32(ip4_route, NM_IP_ROUTE_ATTRIBUTE_MTU, 9000); + nmtst_assert_route_attribute_boolean(ip4_route, NM_IP_ROUTE_ATTRIBUTE_LOCK_MTU, TRUE); + nmtst_assert_route_attribute_boolean(ip4_route, NM_IP_ROUTE_ATTRIBUTE_LOCK_INITCWND, TRUE); + nmtst_assert_route_attribute_string(ip4_route, NM_IP_ROUTE_ATTRIBUTE_SRC, "1.1.1.1"); + nmtst_assert_route_attribute_byte(ip4_route, NM_IP_ROUTE_ATTRIBUTE_SCOPE, 10); + + ip4_route = nm_setting_ip_config_get_route(s_ip4, 2); + g_assert(ip4_route); + g_assert_cmpstr(nm_ip_route_get_dest(ip4_route), ==, "44.55.66.78"); + g_assert_cmpint(nm_ip_route_get_prefix(ip4_route), ==, 32); + g_assert_cmpstr(nm_ip_route_get_next_hop(ip4_route), ==, "192.168.1.8"); + g_assert_cmpint(nm_ip_route_get_metric(ip4_route), ==, 3); + nmtst_assert_route_attribute_byte(ip4_route, NM_IP_ROUTE_ATTRIBUTE_TOS, 0x28); + nmtst_assert_route_attribute_uint32(ip4_route, NM_IP_ROUTE_ATTRIBUTE_WINDOW, 30000); + nmtst_assert_route_attribute_uint32(ip4_route, NM_IP_ROUTE_ATTRIBUTE_CWND, 12); + nmtst_assert_route_attribute_uint32(ip4_route, NM_IP_ROUTE_ATTRIBUTE_INITCWND, 13); + nmtst_assert_route_attribute_uint32(ip4_route, NM_IP_ROUTE_ATTRIBUTE_INITRWND, 14); + nmtst_assert_route_attribute_uint32(ip4_route, NM_IP_ROUTE_ATTRIBUTE_MTU, 9000); + nmtst_assert_route_attribute_boolean(ip4_route, NM_IP_ROUTE_ATTRIBUTE_LOCK_MTU, TRUE); + nmtst_assert_route_attribute_boolean(ip4_route, NM_IP_ROUTE_ATTRIBUTE_LOCK_INITCWND, TRUE); + nmtst_assert_route_attribute_string(ip4_route, NM_IP_ROUTE_ATTRIBUTE_SRC, "1.1.1.1"); + nmtst_assert_route_attribute_boolean(ip4_route, NM_IP_ROUTE_ATTRIBUTE_ONLINK, TRUE); + nmtst_assert_route_attribute_byte(ip4_route, NM_IP_ROUTE_ATTRIBUTE_SCOPE, 253); + + ip4_route = nm_setting_ip_config_get_route(s_ip4, 3); + g_assert(ip4_route); + g_assert_cmpstr(nm_ip_route_get_dest(ip4_route), ==, "1.2.3.4"); + g_assert_cmpint(nm_ip_route_get_prefix(ip4_route), ==, 32); + nmtst_assert_route_attribute_string(ip4_route, NM_IP_ROUTE_ATTRIBUTE_TYPE, "local"); + nmtst_assert_route_attribute_byte(ip4_route, NM_IP_ROUTE_ATTRIBUTE_SCOPE, 254); + + g_object_unref(connection); +} + +static void +test_read_wired_static_routes_legacy(void) +{ + NMConnection * connection; + NMSettingConnection *s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + char * unmanaged = NULL; + NMIPRoute * ip4_route; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-static-routes-legacy", + NULL, + TYPE_ETHERNET, + &unmanaged); + g_assert(!unmanaged); + + /* ===== CONNECTION SETTING ===== */ + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), + ==, + "System test-wired-static-routes-legacy"); + + /* ===== WIRED SETTING ===== */ + + s_wired = nm_connection_get_setting_wired(connection); + g_assert(s_wired); + + /* ===== IPv4 SETTING ===== */ + + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), + ==, + NM_SETTING_IP4_CONFIG_METHOD_MANUAL); + + /* Routes */ + g_assert_cmpint(nm_setting_ip_config_get_num_routes(s_ip4), ==, 5); + + /* Route #1 */ + ip4_route = nm_setting_ip_config_get_route(s_ip4, 0); + g_assert(ip4_route != NULL); + g_assert_cmpstr(nm_ip_route_get_dest(ip4_route), ==, "21.31.41.0"); + g_assert_cmpint(nm_ip_route_get_prefix(ip4_route), ==, 24); + g_assert_cmpstr(nm_ip_route_get_next_hop(ip4_route), ==, "9.9.9.9"); + g_assert_cmpint(nm_ip_route_get_metric(ip4_route), ==, 1); + + /* Route #2 */ + ip4_route = nm_setting_ip_config_get_route(s_ip4, 1); + g_assert(ip4_route != NULL); + g_assert_cmpstr(nm_ip_route_get_dest(ip4_route), ==, "32.42.52.62"); + g_assert_cmpint(nm_ip_route_get_prefix(ip4_route), ==, 32); + g_assert_cmpstr(nm_ip_route_get_next_hop(ip4_route), ==, "8.8.8.8"); + g_assert_cmpint(nm_ip_route_get_metric(ip4_route), ==, -1); + + /* Route #3 */ + ip4_route = nm_setting_ip_config_get_route(s_ip4, 2); + g_assert(ip4_route != NULL); + g_assert_cmpstr(nm_ip_route_get_dest(ip4_route), ==, "43.53.0.0"); + g_assert_cmpint(nm_ip_route_get_prefix(ip4_route), ==, 16); + g_assert_cmpstr(nm_ip_route_get_next_hop(ip4_route), ==, "7.7.7.7"); + g_assert_cmpint(nm_ip_route_get_metric(ip4_route), ==, 3); + nmtst_assert_route_attribute_uint32(ip4_route, NM_IP_ROUTE_ATTRIBUTE_WINDOW, 10000); + nmtst_assert_route_attribute_uint32(ip4_route, NM_IP_ROUTE_ATTRIBUTE_CWND, 14); + nmtst_assert_route_attribute_uint32(ip4_route, NM_IP_ROUTE_ATTRIBUTE_INITCWND, 42); + nmtst_assert_route_attribute_uint32(ip4_route, NM_IP_ROUTE_ATTRIBUTE_INITRWND, 20); + nmtst_assert_route_attribute_uint32(ip4_route, NM_IP_ROUTE_ATTRIBUTE_MTU, 9000); + nmtst_assert_route_attribute_boolean(ip4_route, NM_IP_ROUTE_ATTRIBUTE_LOCK_WINDOW, TRUE); + nmtst_assert_route_attribute_boolean(ip4_route, NM_IP_ROUTE_ATTRIBUTE_LOCK_MTU, TRUE); + nmtst_assert_route_attribute_string(ip4_route, NM_IP_ROUTE_ATTRIBUTE_SRC, "1.2.3.4"); + + ip4_route = nm_setting_ip_config_get_route(s_ip4, 3); + g_assert(ip4_route != NULL); + g_assert_cmpstr(nm_ip_route_get_dest(ip4_route), ==, "7.7.7.8"); + g_assert_cmpint(nm_ip_route_get_prefix(ip4_route), ==, 32); + g_assert_cmpstr(nm_ip_route_get_next_hop(ip4_route), ==, NULL); + g_assert_cmpint(nm_ip_route_get_metric(ip4_route), ==, 18); + + /* Route #5 */ + ip4_route = nm_setting_ip_config_get_route(s_ip4, 4); + g_assert(ip4_route != NULL); + g_assert_cmpstr(nm_ip_route_get_dest(ip4_route), ==, "1.2.3.4"); + nmtst_assert_route_attribute_string(ip4_route, NM_IP_ROUTE_ATTRIBUTE_TYPE, "local"); + + g_object_unref(connection); +} + +static void +test_read_wired_ipv4_manual(gconstpointer data) +{ + NMConnection * connection; + NMSettingConnection *s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + char * unmanaged = NULL; + NMIPAddress * ip4_addr; + const char * file, *expected_id; + + nmtst_test_data_unpack(data, &file, &expected_id); + + g_assert(expected_id); + + connection = _connection_from_file(file, NULL, TYPE_ETHERNET, &unmanaged); + g_assert(!unmanaged); + + /* ===== CONNECTION SETTING ===== */ + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, expected_id); + + /* ===== WIRED SETTING ===== */ + + s_wired = nm_connection_get_setting_wired(connection); + g_assert(s_wired); + + /* ===== IPv4 SETTING ===== */ + + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), + ==, + NM_SETTING_IP4_CONFIG_METHOD_MANUAL); + g_assert_cmpint(nm_setting_ip_config_get_dad_timeout(s_ip4), ==, 2000); + + /* IP addresses */ + g_assert_cmpint(nm_setting_ip_config_get_num_addresses(s_ip4), ==, 3); + + /* Address #1 */ + ip4_addr = nm_setting_ip_config_get_address(s_ip4, 0); + g_assert(ip4_addr != NULL); + g_assert_cmpstr(nm_ip_address_get_address(ip4_addr), ==, "1.2.3.4"); + g_assert_cmpint(nm_ip_address_get_prefix(ip4_addr), ==, 24); + + /* Address #2 */ + ip4_addr = nm_setting_ip_config_get_address(s_ip4, 1); + g_assert(ip4_addr != NULL); + g_assert_cmpstr(nm_ip_address_get_address(ip4_addr), ==, "9.8.7.6"); + g_assert_cmpint(nm_ip_address_get_prefix(ip4_addr), ==, 16); + + /* Address #3 */ + ip4_addr = nm_setting_ip_config_get_address(s_ip4, 2); + g_assert(ip4_addr != NULL); + g_assert_cmpstr(nm_ip_address_get_address(ip4_addr), ==, "3.3.3.3"); + g_assert_cmpint(nm_ip_address_get_prefix(ip4_addr), ==, 8); + + g_object_unref(connection); +} + +static void +test_read_wired_ipv6_manual(void) +{ + NMConnection * connection; + NMSettingConnection *s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + char * unmanaged = NULL; + NMIPAddress * ip6_addr; + NMIPRoute * ip6_route; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-ipv6-manual", + NULL, + TYPE_ETHERNET, + &unmanaged); + g_assert(!unmanaged); + + /* ===== CONNECTION SETTING ===== */ + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-wired-ipv6-manual"); + + /* ===== WIRED SETTING ===== */ + + s_wired = nm_connection_get_setting_wired(connection); + g_assert(s_wired); + + /* ===== IPv4 SETTING ===== */ + + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + + /* DNS Addresses */ + g_assert_cmpint(nm_setting_ip_config_get_num_dns(s_ip4), ==, 2); + + /* DNS search domains */ + g_assert_cmpint(nm_setting_ip_config_get_num_dns_searches(s_ip4), ==, 3); + g_assert_cmpstr(nm_setting_ip_config_get_dns_search(s_ip4, 0), ==, "lorem.com"); + g_assert_cmpstr(nm_setting_ip_config_get_dns_search(s_ip4, 1), ==, "ipsum.org"); + g_assert_cmpstr(nm_setting_ip_config_get_dns_search(s_ip4, 2), ==, "dolor.edu"); + + /* ===== IPv6 SETTING ===== */ + + s_ip6 = nm_connection_get_setting_ip6_config(connection); + g_assert(s_ip6); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip6), + ==, + NM_SETTING_IP6_CONFIG_METHOD_MANUAL); + g_assert(!nm_setting_ip_config_get_never_default(s_ip6)); + g_assert(nm_setting_ip_config_get_may_fail(s_ip6)); + + /* IP addresses */ + g_assert_cmpint(nm_setting_ip_config_get_num_addresses(s_ip6), ==, 3); + + /* Address #1 */ + ip6_addr = nm_setting_ip_config_get_address(s_ip6, 0); + g_assert(ip6_addr != NULL); + g_assert_cmpstr(nm_ip_address_get_address(ip6_addr), ==, "1001:abba::1234"); + g_assert_cmpint(nm_ip_address_get_prefix(ip6_addr), ==, 56); + + /* Address #2 */ + ip6_addr = nm_setting_ip_config_get_address(s_ip6, 1); + g_assert(ip6_addr != NULL); + g_assert_cmpstr(nm_ip_address_get_address(ip6_addr), ==, "2001:abba::2234"); + g_assert_cmpint(nm_ip_address_get_prefix(ip6_addr), ==, 64); + + /* Address #3 */ + ip6_addr = nm_setting_ip_config_get_address(s_ip6, 2); + g_assert(ip6_addr != NULL); + g_assert_cmpstr(nm_ip_address_get_address(ip6_addr), ==, "3001:abba::3234"); + g_assert_cmpint(nm_ip_address_get_prefix(ip6_addr), ==, 96); + + /* Routes */ + g_assert_cmpint(nm_setting_ip_config_get_num_routes(s_ip6), ==, 4); + /* Route #1 */ + ip6_route = nm_setting_ip_config_get_route(s_ip6, 0); + g_assert(ip6_route); + g_assert_cmpstr(nm_ip_route_get_dest(ip6_route), ==, "9876::1234"); + g_assert_cmpint(nm_ip_route_get_prefix(ip6_route), ==, 96); + g_assert_cmpstr(nm_ip_route_get_next_hop(ip6_route), ==, "9876::7777"); + g_assert_cmpint(nm_ip_route_get_metric(ip6_route), ==, 2); + /* Route #2 */ + ip6_route = nm_setting_ip_config_get_route(s_ip6, 1); + g_assert(ip6_route); + g_assert_cmpstr(nm_ip_route_get_dest(ip6_route), ==, "::"); + g_assert_cmpint(nm_ip_route_get_prefix(ip6_route), ==, 0); + g_assert_cmpstr(nm_ip_route_get_next_hop(ip6_route), ==, "dead::beaf"); + g_assert_cmpint(nm_ip_route_get_metric(ip6_route), ==, -1); + /* Route #3 */ + ip6_route = nm_setting_ip_config_get_route(s_ip6, 2); + g_assert(ip6_route); + g_assert_cmpstr(nm_ip_route_get_dest(ip6_route), ==, "abbe::cafe"); + g_assert_cmpint(nm_ip_route_get_prefix(ip6_route), ==, 64); + g_assert_cmpstr(nm_ip_route_get_next_hop(ip6_route), ==, NULL); + g_assert_cmpint(nm_ip_route_get_metric(ip6_route), ==, 777); + /* Route #4 */ + ip6_route = nm_setting_ip_config_get_route(s_ip6, 3); + g_assert(ip6_route); + g_assert_cmpstr(nm_ip_route_get_dest(ip6_route), ==, "aaaa::cccc"); + g_assert_cmpint(nm_ip_route_get_prefix(ip6_route), ==, 64); + g_assert_cmpstr(nm_ip_route_get_next_hop(ip6_route), ==, "3333::4444"); + nmtst_assert_route_attribute_uint32(ip6_route, NM_IP_ROUTE_ATTRIBUTE_CWND, 13); + nmtst_assert_route_attribute_uint32(ip6_route, NM_IP_ROUTE_ATTRIBUTE_MTU, 1450); + nmtst_assert_route_attribute_boolean(ip6_route, NM_IP_ROUTE_ATTRIBUTE_LOCK_MTU, TRUE); + nmtst_assert_route_attribute_string(ip6_route, NM_IP_ROUTE_ATTRIBUTE_FROM, "1111::2222/48"); + nmtst_assert_route_attribute_string(ip6_route, NM_IP_ROUTE_ATTRIBUTE_SRC, "5555::6666"); + + /* DNS Addresses */ + g_assert_cmpint(nm_setting_ip_config_get_num_dns(s_ip6), ==, 2); + g_assert_cmpstr(nm_setting_ip_config_get_dns(s_ip6, 0), ==, "1:2:3:4::a"); + g_assert_cmpstr(nm_setting_ip_config_get_dns(s_ip6, 1), ==, "1:2:3:4::b"); + + /* DNS domains - none as domains are stuffed to 'ipv4' setting */ + g_assert_cmpint(nm_setting_ip_config_get_num_dns_searches(s_ip6), ==, 0); + + g_object_unref(connection); +} + +static void +test_read_wired_ipv6_only(gconstpointer test_data) +{ + NMConnection * connection; + NMSettingConnection *s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + char * unmanaged = NULL; + NMIPAddress * ip6_addr; + const char * method; + const char * file, *expected_id; + + nmtst_test_data_unpack(test_data, &file, &expected_id); + + g_assert(expected_id); + + connection = _connection_from_file(file, NULL, TYPE_ETHERNET, &unmanaged); + g_assert(!unmanaged); + + /* ===== CONNECTION SETTING ===== */ + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, expected_id); + + /* ===== WIRED SETTING ===== */ + + s_wired = nm_connection_get_setting_wired(connection); + g_assert(s_wired); + + /* ===== IPv4 SETTING ===== */ + + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + + method = nm_setting_ip_config_get_method(s_ip4); + g_assert_cmpstr(method, ==, NM_SETTING_IP4_CONFIG_METHOD_DISABLED); + + /* ===== IPv6 SETTING ===== */ + + s_ip6 = nm_connection_get_setting_ip6_config(connection); + g_assert(s_ip6); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip6), + ==, + NM_SETTING_IP6_CONFIG_METHOD_MANUAL); + + /* IP addresses */ + g_assert_cmpint(nm_setting_ip_config_get_num_addresses(s_ip6), ==, 1); + + /* Address #1 */ + ip6_addr = nm_setting_ip_config_get_address(s_ip6, 0); + g_assert(ip6_addr != NULL); + g_assert_cmpstr(nm_ip_address_get_address(ip6_addr), ==, "1001:abba::1234"); + g_assert_cmpint(nm_ip_address_get_prefix(ip6_addr), ==, 56); + + /* DNS Addresses */ + g_assert_cmpint(nm_setting_ip_config_get_num_dns(s_ip6), ==, 1); + g_assert_cmpstr(nm_setting_ip_config_get_dns(s_ip6, 0), ==, "1:2:3:4::a"); + + /* DNS domains should be in IPv6, because IPv4 is disabled */ + g_assert_cmpint(nm_setting_ip_config_get_num_dns_searches(s_ip6), ==, 3); + g_assert_cmpstr(nm_setting_ip_config_get_dns_search(s_ip6, 0), ==, "lorem.com"); + g_assert_cmpstr(nm_setting_ip_config_get_dns_search(s_ip6, 1), ==, "ipsum.org"); + g_assert_cmpstr(nm_setting_ip_config_get_dns_search(s_ip6, 2), ==, "dolor.edu"); + + g_object_unref(connection); +} + +static void +test_read_wired_dhcp6_only(void) +{ + NMConnection * connection; + NMSettingConnection *s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + char * unmanaged = NULL; + const char * method; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-dhcp6-only", + NULL, + TYPE_ETHERNET, + &unmanaged); + g_assert(!unmanaged); + + /* ===== CONNECTION SETTING ===== */ + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-wired-dhcp6-only"); + + /* ===== WIRED SETTING ===== */ + + s_wired = nm_connection_get_setting_wired(connection); + g_assert(s_wired); + + /* ===== IPv4 SETTING ===== */ + + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + + method = nm_setting_ip_config_get_method(s_ip4); + g_assert_cmpstr(method, ==, NM_SETTING_IP4_CONFIG_METHOD_DISABLED); + + /* ===== IPv6 SETTING ===== */ + + s_ip6 = nm_connection_get_setting_ip6_config(connection); + g_assert(s_ip6); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_DHCP); + + g_object_unref(connection); +} + +static void +test_read_wired_autoip(void) +{ + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + char * unmanaged = NULL; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-autoip", + NULL, + TYPE_ETHERNET, + &unmanaged); + g_assert(unmanaged == NULL); + + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), + ==, + NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL); + g_assert(!nm_setting_ip_config_get_may_fail(s_ip4)); + g_assert(nm_setting_ip_config_get_ignore_auto_dns(s_ip4)); + + s_con = nm_connection_get_setting_connection(connection); + g_assert_cmpint(nm_setting_connection_get_wait_device_timeout(s_con), ==, 2600); +} + +static void +test_read_onboot_no(void) +{ + NMConnection * connection; + NMSettingConnection *s_con; + char * unmanaged = NULL; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-onboot-no", + NULL, + TYPE_ETHERNET, + &unmanaged); + g_assert(!unmanaged); + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + + g_assert(!nm_setting_connection_get_autoconnect(s_con)); + + g_object_unref(connection); +} + +static void +test_read_noip(void) +{ + NMConnection * connection; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + + connection = + _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-noip", NULL, TYPE_ETHERNET, NULL); + + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), + ==, + NM_SETTING_IP4_CONFIG_METHOD_DISABLED); + g_assert(nm_setting_ip_config_get_never_default(s_ip4) == FALSE); + + s_ip6 = nm_connection_get_setting_ip6_config(connection); + g_assert(s_ip6); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip6), + ==, + NM_SETTING_IP6_CONFIG_METHOD_IGNORE); + g_assert(nm_setting_ip_config_get_never_default(s_ip6) == FALSE); + + g_object_unref(connection); +} + +#define TEST_IFCFG_WIRED_8021x_PEAP_MSCHAPV2_CA_CERT TEST_IFCFG_DIR "/test_ca_cert.pem" + +static void +test_read_wired_8021x_peap_mschapv2(void) +{ + NMConnection * connection; + NMSettingWired * s_wired; + NMSettingIPConfig *s_ip4; + NMSetting8021x * s_8021x; + NMSetting8021x * tmp_8021x; + char * unmanaged = NULL; + GError * error = NULL; + gboolean success = FALSE; + const char * expected_ca_cert_path; + const char * read_ca_cert_path; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-8021x-peap-mschapv2", + NULL, + TYPE_ETHERNET, + &unmanaged); + g_assert(!unmanaged); + + /* ===== WIRED SETTING ===== */ + + s_wired = nm_connection_get_setting_wired(connection); + g_assert(s_wired); + + /* ===== IPv4 SETTING ===== */ + + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); + + /* ===== 802.1x SETTING ===== */ + s_8021x = nm_connection_get_setting_802_1x(connection); + g_assert(s_8021x); + + g_assert_cmpint(nm_setting_802_1x_get_num_eap_methods(s_8021x), ==, 1); + g_assert_cmpstr(nm_setting_802_1x_get_eap_method(s_8021x, 0), ==, "peap"); + g_assert_cmpstr(nm_setting_802_1x_get_identity(s_8021x), ==, "David Smith"); + g_assert_cmpstr(nm_setting_802_1x_get_anonymous_identity(s_8021x), ==, "somebody"); + g_assert_cmpstr(nm_setting_802_1x_get_password(s_8021x), ==, "foobar baz"); + g_assert_cmpstr(nm_setting_802_1x_get_phase1_peapver(s_8021x), ==, "1"); + g_assert_cmpstr(nm_setting_802_1x_get_phase1_peaplabel(s_8021x), ==, "1"); + + /* CA Cert */ + tmp_8021x = (NMSetting8021x *) nm_setting_802_1x_new(); + + success = nm_setting_802_1x_set_ca_cert(tmp_8021x, + TEST_IFCFG_WIRED_8021x_PEAP_MSCHAPV2_CA_CERT, + NM_SETTING_802_1X_CK_SCHEME_PATH, + NULL, + &error); + g_assert_no_error(error); + g_assert(success == TRUE); + + expected_ca_cert_path = nm_setting_802_1x_get_ca_cert_path(tmp_8021x); + g_assert(expected_ca_cert_path); + + read_ca_cert_path = nm_setting_802_1x_get_ca_cert_path(s_8021x); + g_assert(read_ca_cert_path); + + g_assert_cmpstr(read_ca_cert_path, ==, expected_ca_cert_path); + + g_object_unref(tmp_8021x); + + g_object_unref(connection); +} + +static void +test_read_wired_8021x_tls_secret_flags(gconstpointer test_data) +{ + NMConnection * connection; + NMSettingWired *s_wired; + NMSetting8021x *s_8021x; + char * dirname, *tmp; + const char * ifcfg; + gpointer expected_flags_p; + + nmtst_test_data_unpack(test_data, &ifcfg, &expected_flags_p); + + connection = _connection_from_file(ifcfg, NULL, TYPE_ETHERNET, NULL); + + /* ===== WIRED SETTING ===== */ + s_wired = nm_connection_get_setting_wired(connection); + g_assert(s_wired); + + /* ===== 802.1x SETTING ===== */ + s_8021x = nm_connection_get_setting_802_1x(connection); + g_assert(s_8021x); + g_assert_cmpint(nm_setting_802_1x_get_num_eap_methods(s_8021x), ==, 1); + g_assert_cmpstr(nm_setting_802_1x_get_eap_method(s_8021x, 0), ==, "tls"); + g_assert_cmpstr(nm_setting_802_1x_get_identity(s_8021x), ==, "David Smith"); + g_assert_cmpint(nm_setting_802_1x_get_private_key_password_flags(s_8021x), + ==, + GPOINTER_TO_INT(expected_flags_p)); + + dirname = g_path_get_dirname(ifcfg); + tmp = g_build_path("/", dirname, "test_ca_cert.pem", NULL); + g_assert_cmpstr(nm_setting_802_1x_get_ca_cert_path(s_8021x), ==, tmp); + g_free(tmp); + + tmp = g_build_path("/", dirname, "test1_key_and_cert.pem", NULL); + g_assert_cmpstr(nm_setting_802_1x_get_client_cert_path(s_8021x), ==, tmp); + g_assert_cmpstr(nm_setting_802_1x_get_private_key_path(s_8021x), ==, tmp); + g_free(tmp); + + g_free(dirname); + + g_object_unref(connection); +} + +static void +test_read_write_802_1X_subj_matches(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSetting8021x * s_8021x; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-802-1X-subj-matches", + NULL, + TYPE_ETHERNET, + NULL); + + /* ===== 802.1x SETTING ===== */ + s_8021x = nm_connection_get_setting_802_1x(connection); + g_assert(s_8021x); + g_assert_cmpint(nm_setting_802_1x_get_num_eap_methods(s_8021x), ==, 1); + g_assert_cmpstr(nm_setting_802_1x_get_eap_method(s_8021x, 0), ==, "peap"); + g_assert_cmpstr(nm_setting_802_1x_get_identity(s_8021x), ==, "Jara Cimrman"); + g_assert_cmpstr(nm_setting_802_1x_get_subject_match(s_8021x), ==, "server1.yourdomain.tld"); + g_assert_cmpstr(nm_setting_802_1x_get_phase2_subject_match(s_8021x), + ==, + "server2.yourdomain.tld"); + g_assert_cmpint(nm_setting_802_1x_get_num_altsubject_matches(s_8021x), ==, 3); + g_assert_cmpstr(nm_setting_802_1x_get_altsubject_match(s_8021x, 0), ==, "a.yourdomain.tld"); + g_assert_cmpstr(nm_setting_802_1x_get_altsubject_match(s_8021x, 1), ==, "b.yourdomain.tld"); + g_assert_cmpstr(nm_setting_802_1x_get_altsubject_match(s_8021x, 2), ==, "c.yourdomain.tld"); + g_assert_cmpint(nm_setting_802_1x_get_num_phase2_altsubject_matches(s_8021x), ==, 2); + g_assert_cmpstr(nm_setting_802_1x_get_phase2_altsubject_match(s_8021x, 0), + ==, + "x.yourdomain.tld"); + g_assert_cmpstr(nm_setting_802_1x_get_phase2_altsubject_match(s_8021x, 1), + ==, + "y.yourdomain.tld"); + + _writer_new_connec_exp(connection, + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR "/ifcfg-System_test-wired-802-1X-subj-matches.cexpected", + &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); + + /* Check 802.1X stuff of the re-read connection. */ + s_8021x = nm_connection_get_setting_802_1x(reread); + g_assert(s_8021x); + g_assert_cmpint(nm_setting_802_1x_get_num_eap_methods(s_8021x), ==, 1); + g_assert_cmpstr(nm_setting_802_1x_get_eap_method(s_8021x, 0), ==, "peap"); + g_assert_cmpstr(nm_setting_802_1x_get_identity(s_8021x), ==, "Jara Cimrman"); + g_assert_cmpstr(nm_setting_802_1x_get_subject_match(s_8021x), ==, "server1.yourdomain.tld"); + g_assert_cmpstr(nm_setting_802_1x_get_phase2_subject_match(s_8021x), + ==, + "server2.yourdomain.tld"); + g_assert_cmpint(nm_setting_802_1x_get_num_altsubject_matches(s_8021x), ==, 3); + g_assert_cmpstr(nm_setting_802_1x_get_altsubject_match(s_8021x, 0), ==, "a.yourdomain.tld"); + g_assert_cmpstr(nm_setting_802_1x_get_altsubject_match(s_8021x, 1), ==, "b.yourdomain.tld"); + g_assert_cmpstr(nm_setting_802_1x_get_altsubject_match(s_8021x, 2), ==, "c.yourdomain.tld"); + g_assert_cmpint(nm_setting_802_1x_get_num_phase2_altsubject_matches(s_8021x), ==, 2); + g_assert_cmpstr(nm_setting_802_1x_get_phase2_altsubject_match(s_8021x, 0), + ==, + "x.yourdomain.tld"); + g_assert_cmpstr(nm_setting_802_1x_get_phase2_altsubject_match(s_8021x, 1), + ==, + "y.yourdomain.tld"); +} + +static void +test_read_802_1x_ttls_eapgtc(void) +{ + NMConnection * connection; + NMSetting8021x *s_8021x; + + /* Test that EAP-* inner methods are correctly read into the + * NMSetting8021x::autheap property. + */ + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-802-1x-ttls-eapgtc", + NULL, + TYPE_WIRELESS, + NULL); + + /* ===== 802.1x SETTING ===== */ + s_8021x = nm_connection_get_setting_802_1x(connection); + g_assert(s_8021x); + + /* EAP methods */ + g_assert_cmpint(nm_setting_802_1x_get_num_eap_methods(s_8021x), ==, 1); + g_assert_cmpstr(nm_setting_802_1x_get_eap_method(s_8021x, 0), ==, "ttls"); + + /* Auth methods */ + g_assert_cmpstr(nm_setting_802_1x_get_phase2_auth(s_8021x), ==, NULL); + g_assert_cmpstr(nm_setting_802_1x_get_phase2_autheap(s_8021x), ==, "gtc"); + + g_object_unref(connection); +} + +static void +test_read_802_1x_tls_p12_no_client_cert(void) +{ + gs_unref_object NMConnection *connection = NULL; + NMSetting8021x * s_8021x; + const char * path; + + connection = + _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-8021x-tls-p12-no-client-cert", + NULL, + TYPE_ETHERNET, + NULL); + + s_8021x = nm_connection_get_setting_802_1x(connection); + g_assert(s_8021x); + + g_assert_cmpint(nm_setting_802_1x_get_private_key_scheme(s_8021x), + ==, + NM_SETTING_802_1X_CK_SCHEME_PATH); + path = nm_setting_802_1x_get_private_key_path(s_8021x); + g_assert(path); + + g_assert_cmpint(nm_setting_802_1x_get_client_cert_scheme(s_8021x), + ==, + NM_SETTING_802_1X_CK_SCHEME_PATH); + g_assert_cmpstr(path, ==, nm_setting_802_1x_get_client_cert_path(s_8021x)); +} + +static void +test_read_write_802_1x_password_raw(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSetting8021x * s_8021x; + GBytes * bytes; + gconstpointer data; + gsize size; + + /* Test that the 802-1x.password-raw is correctly read and written. */ + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-802-1x-password-raw", + NULL, + TYPE_ETHERNET, + NULL); + + /* ===== 802.1x SETTING ===== */ + s_8021x = nm_connection_get_setting_802_1x(connection); + g_assert(s_8021x); + + bytes = nm_setting_802_1x_get_password_raw(s_8021x); + g_assert(bytes); + data = g_bytes_get_data(bytes, &size); + g_assert_cmpmem(data, size, "\x04\x08\x15\x16\x23\x42\x00\x01", 8); + + g_assert_cmpint(nm_setting_802_1x_get_password_raw_flags(s_8021x), + ==, + NM_SETTING_SECRET_FLAG_NONE); + + g_assert_cmpstr(nm_setting_802_1x_get_pin(s_8021x), ==, "hallo2"); + g_assert_cmpint(nm_setting_802_1x_get_pin_flags(s_8021x), ==, NM_SETTING_SECRET_FLAG_NONE); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + keyfile = utils_get_keys_path(testfile); + g_assert(g_file_test(keyfile, G_FILE_TEST_EXISTS)); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_read_wired_aliases_good(gconstpointer test_data) +{ + const int N = GPOINTER_TO_INT(test_data); + NMConnection * connection; + NMSettingConnection *s_con; + NMSettingIPConfig * s_ip4; + int expected_num_addresses; + const char * expected_address_0[] = {"192.168.1.5", + "192.168.1.6", + "192.168.1.9", + "192.168.1.99", + NULL}; + const char * expected_address_3[] = {"192.168.1.5", "192.168.1.6", NULL}; + const char * expected_label_0[] = { + NULL, + "aliasem0:1", + "aliasem0:2", + "aliasem0:99", + NULL, + }; + const char *expected_label_3[] = { + NULL, + "aliasem3:1", + NULL, + }; + const char **expected_address; + const char **expected_label; + int i, j; + char path[256]; + + expected_address = N == 0 ? expected_address_0 : expected_address_3; + expected_label = N == 0 ? expected_label_0 : expected_label_3; + expected_num_addresses = g_strv_length((char **) expected_address); + + nm_sprintf_buf(path, TEST_IFCFG_DIR "/ifcfg-aliasem%d", N); + + connection = _connection_from_file(path, NULL, TYPE_ETHERNET, NULL); + + /* ===== CONNECTION SETTING ===== */ + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + if (N == 0) + g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System aliasem0"); + else + g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System aliasem3"); + + /* ===== IPv4 SETTING ===== */ + + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), + ==, + NM_SETTING_IP4_CONFIG_METHOD_MANUAL); + g_assert_cmpint(nm_setting_ip_config_get_num_addresses(s_ip4), ==, expected_num_addresses); + + /* Addresses */ + for (i = 0; i < expected_num_addresses; i++) { + NMIPAddress *ip4_addr; + const char * addr; + GVariant * label; + + ip4_addr = nm_setting_ip_config_get_address(s_ip4, i); + g_assert(ip4_addr != NULL); + + addr = nm_ip_address_get_address(ip4_addr); + g_assert(nm_utils_ipaddr_is_valid(AF_INET, addr)); + + for (j = 0; j < expected_num_addresses; j++) { + if (!g_strcmp0(addr, expected_address[j])) + break; + } + g_assert(j < expected_num_addresses); + + g_assert_cmpint(nm_ip_address_get_prefix(ip4_addr), ==, 24); + label = nm_ip_address_get_attribute(ip4_addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL); + if (expected_label[j]) + g_assert_cmpstr(g_variant_get_string(label, NULL), ==, expected_label[j]); + else + g_assert(label == NULL); + + expected_address[j] = NULL; + expected_label[j] = NULL; + } + + /* Gateway */ + g_assert(!nm_setting_ip_config_get_never_default(s_ip4)); + g_assert_cmpstr(nm_setting_ip_config_get_gateway(s_ip4), ==, "192.168.1.1"); + + for (i = 0; i < expected_num_addresses; i++) + g_assert(!expected_address[i]); + + g_object_unref(connection); +} + +static void +test_read_wired_aliases_bad(const char *base, const char *expected_id) +{ + NMConnection * connection; + NMSettingConnection *s_con; + NMSettingIPConfig * s_ip4; + NMIPAddress * ip4_addr; + + g_assert(expected_id); + + connection = _connection_from_file(base, NULL, TYPE_ETHERNET, NULL); + g_test_assert_expected_messages(); + + /* ===== CONNECTION SETTING ===== */ + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, expected_id); + + /* ===== IPv4 SETTING ===== */ + + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), + ==, + NM_SETTING_IP4_CONFIG_METHOD_MANUAL); + + g_assert_cmpint(nm_setting_ip_config_get_num_addresses(s_ip4), ==, 1); + + /* Addresses */ + ip4_addr = nm_setting_ip_config_get_address(s_ip4, 0); + g_assert(ip4_addr != NULL); + g_assert_cmpstr(nm_ip_address_get_address(ip4_addr), ==, "192.168.1.5"); + g_assert_cmpint(nm_ip_address_get_prefix(ip4_addr), ==, 24); + g_assert(nm_ip_address_get_attribute(ip4_addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL) == NULL); + + /* Gateway */ + g_assert_cmpstr(nm_setting_ip_config_get_gateway(s_ip4), ==, "192.168.1.1"); + + g_object_unref(connection); +} + +static void +test_read_wired_aliases_bad_1(void) +{ + NMTST_EXPECT_NM_WARN("*aliasem1:1*has no DEVICE*"); + test_read_wired_aliases_bad(TEST_IFCFG_DIR "/ifcfg-aliasem1", "System aliasem1"); +} + +static void +test_read_wired_aliases_bad_2(void) +{ + NMTST_EXPECT_NM_WARN("*aliasem2:1*has invalid DEVICE*"); + test_read_wired_aliases_bad(TEST_IFCFG_DIR "/ifcfg-aliasem2", "System aliasem2"); +} + +static void +test_read_dns_options(void) +{ + NMConnection * connection; + NMSettingIPConfig *s_ip4, *s_ip6; + char * unmanaged = NULL; + const char * option; + const char * options4[] = {"ndots:3", "single-request-reopen"}; + const char * options6[] = {"inet6"}; + guint32 i, num; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-dns-options", + NULL, + TYPE_ETHERNET, + &unmanaged); + g_assert_cmpstr(unmanaged, ==, NULL); + + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + + s_ip6 = nm_connection_get_setting_ip6_config(connection); + g_assert(s_ip6); + + num = nm_setting_ip_config_get_num_dns_options(s_ip4); + g_assert_cmpint(num, ==, G_N_ELEMENTS(options4)); + + for (i = 0; i < num; i++) { + option = nm_setting_ip_config_get_dns_option(s_ip4, i); + g_assert_cmpstr(options4[i], ==, option); + } + + num = nm_setting_ip_config_get_num_dns_options(s_ip6); + g_assert_cmpint(num, ==, G_N_ELEMENTS(options6)); + + for (i = 0; i < num; i++) { + option = nm_setting_ip_config_get_dns_option(s_ip6, i); + g_assert_cmpstr(options6[i], ==, option); + } + + g_object_unref(connection); +} + +static void +test_clear_master(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_free char * keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + char * unmanaged = NULL; + shvarFile * f; + + /* 1. load the bridge slave connection from disk */ + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bridge-component", + NULL, + TYPE_ETHERNET, + &unmanaged); + g_assert_cmpstr(unmanaged, ==, NULL); + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + + g_assert_cmpstr(nm_setting_connection_get_master(s_con), ==, "br0"); + g_assert_cmpstr(nm_setting_connection_get_slave_type(s_con), ==, "bridge"); + + /* 2. write the connection to a new file */ + _writer_new_connec_exp(connection, + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR "/ifcfg-System_test-bridge-component-a.cexpected", + &testfile); + + /* 3. clear master and slave-type */ + g_object_set(s_con, + NM_SETTING_CONNECTION_MASTER, + NULL, + NM_SETTING_CONNECTION_SLAVE_TYPE, + NULL, + NULL); + + g_assert_cmpstr(nm_setting_connection_get_master(s_con), ==, NULL); + g_assert_cmpstr(nm_setting_connection_get_slave_type(s_con), ==, NULL); + + nmtst_assert_connection_verifies_after_normalization(connection, 0, 0); + + /* 4. update the connection on disk */ + _writer_update_connection(connection, + TEST_SCRATCH_DIR, + testfile, + TEST_IFCFG_DIR "/ifcfg-System_test-bridge-component-b.cexpected"); + keyfile = utils_get_keys_path(testfile); + g_assert(!g_file_test(keyfile, G_FILE_TEST_EXISTS)); + + /* 5. check that BRIDGE variable has been removed */ + f = _svOpenFile(testfile); + _svGetValue_check(f, "BRIDGE", NULL); + svCloseFile(f); +} + +static void +test_write_dns_options(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + static const char * mac = "31:33:33:37:be:cd"; + guint32 mtu = 1492; + NMIPAddress * addr; + NMIPAddress * addr6; + GError * error = NULL; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test DNS options", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRED_SETTING_NAME, + NULL); + + /* Wired setting */ + s_wired = (NMSettingWired *) nm_setting_wired_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wired)); + + g_object_set(s_wired, NM_SETTING_WIRED_MAC_ADDRESS, mac, NM_SETTING_WIRED_MTU, mtu, NULL); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP4_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NM_SETTING_IP_CONFIG_GATEWAY, + "1.1.1.1", + NM_SETTING_IP_CONFIG_ROUTE_METRIC, + (gint64) 204, + NULL); + + addr = nm_ip_address_new(AF_INET, "1.1.1.3", 24, &error); + nm_setting_ip_config_add_address(s_ip4, addr); + nm_ip_address_unref(addr); + + nm_setting_ip_config_add_dns_option(s_ip4, "debug"); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP6_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NM_SETTING_IP_CONFIG_ROUTE_METRIC, + (gint64) 206, + NULL); + + /* Add addresses */ + addr6 = nm_ip_address_new(AF_INET6, "1003:1234:abcd::1", 11, &error); + nm_setting_ip_config_add_address(s_ip6, addr6); + nm_ip_address_unref(addr6); + + nm_setting_ip_config_add_dns_option(s_ip6, "timeout:3"); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_read_wifi_open(void) +{ + NMConnection * connection; + NMSettingConnection * s_con; + NMSettingWireless * s_wireless; + NMSettingWirelessSecurity *s_wsec; + NMSettingIPConfig * s_ip4, *s_ip6; + GBytes * ssid; + const char * mac; + char expected_mac_address[ETH_ALEN] = {0x00, 0x16, 0x41, 0x11, 0x22, 0x33}; + const char *expected_ssid = "blahblah"; + + connection = + _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-open", NULL, TYPE_WIRELESS, NULL); + + /* ===== CONNECTION SETTING ===== */ + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System blahblah (test-wifi-open)"); + + /* UUID can't be tested if the ifcfg does not contain the UUID key, because + * the UUID is generated on the full path of the ifcfg file, which can change + * depending on where the tests are run. + */ + + g_assert_cmpint(nm_setting_connection_get_timestamp(s_con), ==, 0); + g_assert(nm_setting_connection_get_autoconnect(s_con)); + g_assert_cmpint(nm_setting_connection_get_autoconnect_priority(s_con), ==, -1); + + /* ===== WIRELESS SETTING ===== */ + + s_wireless = nm_connection_get_setting_wireless(connection); + g_assert(s_wireless); + + /* MAC address */ + mac = nm_setting_wireless_get_mac_address(s_wireless); + g_assert(mac); + g_assert(nm_utils_hwaddr_matches(mac, -1, expected_mac_address, sizeof(expected_mac_address))); + + g_assert_cmpint(nm_setting_wireless_get_mtu(s_wireless), ==, 0); + + ssid = nm_setting_wireless_get_ssid(s_wireless); + g_assert(ssid); + g_assert_cmpmem(g_bytes_get_data(ssid, NULL), + g_bytes_get_size(ssid), + expected_ssid, + strlen(expected_ssid)); + + g_assert(!nm_setting_wireless_get_bssid(s_wireless)); + g_assert_cmpstr(nm_setting_wireless_get_mode(s_wireless), ==, "infrastructure"); + g_assert_cmpint(nm_setting_wireless_get_channel(s_wireless), ==, 1); + + /* ===== Wi-Fi SECURITY SETTING ===== */ + s_wsec = nm_connection_get_setting_wireless_security(connection); + g_assert(s_wsec == NULL); + + /* ===== IPv4 SETTING ===== */ + + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + g_assert_cmpint(nm_setting_ip_config_get_route_metric(s_ip4), ==, 104); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); + + s_ip6 = nm_connection_get_setting_ip6_config(connection); + g_assert(s_ip6); + g_assert_cmpint(nm_setting_ip_config_get_route_metric(s_ip6), ==, 106); + + g_object_unref(connection); +} + +static void +test_read_wifi_open_auto(void) +{ + NMConnection * connection; + NMSettingConnection *s_con; + NMSettingWireless * s_wireless; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-open-auto", + NULL, + TYPE_WIRELESS, + NULL); + + /* ===== CONNECTION SETTING ===== */ + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), + ==, + "System blahblah (test-wifi-open-auto)"); + + /* ===== WIRELESS SETTING ===== */ + s_wireless = nm_connection_get_setting_wireless(connection); + g_assert(s_wireless); + g_assert_cmpstr(nm_setting_wireless_get_mode(s_wireless), ==, "infrastructure"); + + g_object_unref(connection); +} + +static void +test_read_wifi_open_ssid_hex(void) +{ + NMConnection * connection; + NMSettingConnection *s_con; + NMSettingWireless * s_wireless; + GBytes * ssid; + const char * expected_ssid = "blahblah"; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-open-ssid-hex", + NULL, + TYPE_WIRELESS, + NULL); + + /* ===== CONNECTION SETTING ===== */ + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), + ==, + "System blahblah (test-wifi-open-ssid-hex)"); + + /* ===== WIRELESS SETTING ===== */ + + s_wireless = nm_connection_get_setting_wireless(connection); + g_assert(s_wireless); + + ssid = nm_setting_wireless_get_ssid(s_wireless); + g_assert(ssid); + g_assert_cmpmem(g_bytes_get_data(ssid, NULL), + g_bytes_get_size(ssid), + expected_ssid, + strlen(expected_ssid)); + + g_object_unref(connection); +} + +static void +test_read_wifi_open_ssid_hex_bad(void) +{ + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wireless; + GBytes * ssid; + const char * expected_ssid = "0x626cxx"; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-open-ssid-bad-hex", + NULL, + TYPE_WIRELESS, + NULL); + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), + ==, + "System 0x626cxx (test-wifi-open-ssid-bad-hex)"); + + s_wireless = nm_connection_get_setting_wireless(connection); + g_assert(s_wireless); + + ssid = nm_setting_wireless_get_ssid(s_wireless); + g_assert(ssid); + g_assert_cmpmem(g_bytes_get_data(ssid, NULL), + g_bytes_get_size(ssid), + expected_ssid, + strlen(expected_ssid)); +} + +static void +test_read_wifi_open_ssid_bad(gconstpointer data) +{ + _connection_from_file_fail((const char *) data, NULL, TYPE_WIRELESS, NULL); +} + +static void +test_read_wifi_open_ssid_quoted(void) +{ + NMConnection * connection; + NMSettingConnection *s_con; + NMSettingWireless * s_wireless; + GBytes * ssid; + const char * expected_ssid = "foo\"bar\\"; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-open-ssid-quoted", + NULL, + TYPE_WIRELESS, + NULL); + + /* ===== CONNECTION SETTING ===== */ + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), + ==, + "System foo\"bar\\ (test-wifi-open-ssid-quoted)"); + + /* ===== WIRELESS SETTING ===== */ + + s_wireless = nm_connection_get_setting_wireless(connection); + g_assert(s_wireless); + + ssid = nm_setting_wireless_get_ssid(s_wireless); + g_assert(ssid); + g_assert_cmpmem(g_bytes_get_data(ssid, NULL), + g_bytes_get_size(ssid), + expected_ssid, + strlen(expected_ssid)); + + g_object_unref(connection); +} + +static void +test_read_wifi_wep(void) +{ + NMConnection * connection; + NMSettingConnection * s_con; + NMSettingWireless * s_wireless; + NMSettingWirelessSecurity *s_wsec; + NMSettingIPConfig * s_ip4; + GBytes * ssid; + const char * mac; + char expected_mac_address[ETH_ALEN] = {0x00, 0x16, 0x41, 0x11, 0x22, 0x33}; + const char * expected_ssid = "blahblah"; + NMWepKeyType key_type; + + connection = + _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wep", NULL, TYPE_WIRELESS, NULL); + + /* ===== CONNECTION SETTING ===== */ + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System blahblah (test-wifi-wep)"); + + /* UUID can't be tested if the ifcfg does not contain the UUID key, because + * the UUID is generated on the full path of the ifcfg file, which can change + * depending on where the tests are run. + */ + + g_assert_cmpint(nm_setting_connection_get_timestamp(s_con), ==, 0); + g_assert(nm_setting_connection_get_autoconnect(s_con)); + + /* ===== WIRELESS SETTING ===== */ + + s_wireless = nm_connection_get_setting_wireless(connection); + g_assert(s_wireless); + + /* MAC address */ + mac = nm_setting_wireless_get_mac_address(s_wireless); + g_assert(mac); + g_assert(nm_utils_hwaddr_matches(mac, -1, expected_mac_address, sizeof(expected_mac_address))); + + /* MTU */ + g_assert_cmpint(nm_setting_wireless_get_mtu(s_wireless), ==, 0); + + ssid = nm_setting_wireless_get_ssid(s_wireless); + g_assert(ssid); + g_assert_cmpmem(g_bytes_get_data(ssid, NULL), + g_bytes_get_size(ssid), + expected_ssid, + strlen(expected_ssid)); + + g_assert(!nm_setting_wireless_get_bssid(s_wireless)); + g_assert_cmpstr(nm_setting_wireless_get_mode(s_wireless), ==, "infrastructure"); + g_assert_cmpint(nm_setting_wireless_get_channel(s_wireless), ==, 1); + + /* ===== WIRELESS SECURITY SETTING ===== */ + + s_wsec = nm_connection_get_setting_wireless_security(connection); + g_assert(s_wsec); + g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "none"); + g_assert_cmpstr(nm_setting_wireless_security_get_auth_alg(s_wsec), ==, "shared"); + g_assert_cmpint(nm_setting_wireless_security_get_wep_tx_keyidx(s_wsec), ==, 0); + + key_type = nm_setting_wireless_security_get_wep_key_type(s_wsec); + g_assert(key_type == NM_WEP_KEY_TYPE_UNKNOWN || key_type == NM_WEP_KEY_TYPE_KEY); + + g_assert_cmpstr(nm_setting_wireless_security_get_wep_key(s_wsec, 0), + ==, + "0123456789abcdef0123456789"); + g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 1)); + g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 2)); + g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 3)); + + /* ===== IPv4 SETTING ===== */ + + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); + + g_object_unref(connection); +} + +static void +test_read_wifi_wep_adhoc(void) +{ + NMConnection * connection; + NMSettingConnection * s_con; + NMSettingWireless * s_wireless; + NMSettingWirelessSecurity *s_wsec; + NMSettingIPConfig * s_ip4; + GBytes * ssid; + const char * expected_ssid = "blahblah"; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wep-adhoc", + NULL, + TYPE_WIRELESS, + NULL); + + /* ===== CONNECTION SETTING ===== */ + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), + ==, + "System blahblah (test-wifi-wep-adhoc)"); + + /* UUID can't be tested if the ifcfg does not contain the UUID key, because + * the UUID is generated on the full path of the ifcfg file, which can change + * depending on where the tests are run. + */ + + g_assert(!nm_setting_connection_get_autoconnect(s_con)); + + /* ===== WIRELESS SETTING ===== */ + + s_wireless = nm_connection_get_setting_wireless(connection); + g_assert(s_wireless); + + ssid = nm_setting_wireless_get_ssid(s_wireless); + g_assert(ssid); + g_assert_cmpmem(g_bytes_get_data(ssid, NULL), + g_bytes_get_size(ssid), + expected_ssid, + strlen(expected_ssid)); + + g_assert(!nm_setting_wireless_get_bssid(s_wireless)); + g_assert_cmpstr(nm_setting_wireless_get_mode(s_wireless), ==, "adhoc"); + g_assert_cmpint(nm_setting_wireless_get_channel(s_wireless), ==, 11); + + /* ===== WIRELESS SECURITY SETTING ===== */ + + s_wsec = nm_connection_get_setting_wireless_security(connection); + g_assert(s_wsec); + g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "none"); + g_assert(!nm_setting_wireless_security_get_auth_alg(s_wsec)); + g_assert_cmpint(nm_setting_wireless_security_get_wep_tx_keyidx(s_wsec), ==, 0); + + g_assert_cmpstr(nm_setting_wireless_security_get_wep_key(s_wsec, 0), + ==, + "0123456789abcdef0123456789"); + g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 1)); + g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 2)); + g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 3)); + + /* ===== IPv4 SETTING ===== */ + + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); + + /* Ignore auto DNS */ + g_assert(nm_setting_ip_config_get_ignore_auto_dns(s_ip4)); + + /* DNS Addresses */ + g_assert_cmpint(nm_setting_ip_config_get_num_dns(s_ip4), ==, 2); + g_assert_cmpstr(nm_setting_ip_config_get_dns(s_ip4, 0), ==, "4.2.2.1"); + g_assert_cmpstr(nm_setting_ip_config_get_dns(s_ip4, 1), ==, "4.2.2.2"); + + g_object_unref(connection); +} + +static void +test_read_wifi_wep_passphrase(void) +{ + NMConnection * connection; + NMSettingConnection * s_con; + NMSettingWireless * s_wireless; + NMSettingWirelessSecurity *s_wsec; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wep-passphrase", + NULL, + TYPE_WIRELESS, + NULL); + + /* ===== CONNECTION SETTING ===== */ + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + + /* ===== WIRELESS SETTING ===== */ + + s_wireless = nm_connection_get_setting_wireless(connection); + g_assert(s_wireless); + + /* ===== WIRELESS SECURITY SETTING ===== */ + + s_wsec = nm_connection_get_setting_wireless_security(connection); + g_assert(s_wsec); + g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "none"); + g_assert_cmpint(nm_setting_wireless_security_get_wep_tx_keyidx(s_wsec), ==, 0); + g_assert_cmpint(nm_setting_wireless_security_get_wep_key_type(s_wsec), + ==, + NM_WEP_KEY_TYPE_UNKNOWN); + g_assert_cmpstr(nm_setting_wireless_security_get_wep_key(s_wsec, 0), ==, "foobar222blahblah"); + g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 1)); + g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 2)); + g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 3)); + + g_object_unref(connection); +} + +static void +test_read_wifi_wep_40_ascii(void) +{ + NMConnection * connection; + NMSettingConnection * s_con; + NMSettingWireless * s_wireless; + NMSettingWirelessSecurity *s_wsec; + NMWepKeyType key_type; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wep-40-ascii", + NULL, + TYPE_WIRELESS, + NULL); + + /* ===== CONNECTION SETTING ===== */ + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + + /* ===== WIRELESS SETTING ===== */ + + s_wireless = nm_connection_get_setting_wireless(connection); + g_assert(s_wireless); + + /* ===== WIRELESS SECURITY SETTING ===== */ + + s_wsec = nm_connection_get_setting_wireless_security(connection); + g_assert(s_wsec); + g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "none"); + g_assert_cmpint(nm_setting_wireless_security_get_wep_tx_keyidx(s_wsec), ==, 0); + + key_type = nm_setting_wireless_security_get_wep_key_type(s_wsec); + g_assert(key_type == NM_WEP_KEY_TYPE_UNKNOWN || key_type == NM_WEP_KEY_TYPE_KEY); + + g_assert_cmpstr(nm_setting_wireless_security_get_wep_key(s_wsec, 0), ==, "Lorem"); + g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 1)); + g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 2)); + g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 3)); + + g_object_unref(connection); +} + +static void +test_read_wifi_wep_104_ascii(void) +{ + NMConnection * connection; + NMSettingConnection * s_con; + NMSettingWireless * s_wireless; + NMSettingWirelessSecurity *s_wsec; + NMWepKeyType key_type; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wep-104-ascii", + NULL, + TYPE_WIRELESS, + NULL); + + /* ===== CONNECTION SETTING ===== */ + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + + /* ===== WIRELESS SETTING ===== */ + + s_wireless = nm_connection_get_setting_wireless(connection); + g_assert(s_wireless); + + /* ===== WIRELESS SECURITY SETTING ===== */ + + s_wsec = nm_connection_get_setting_wireless_security(connection); + g_assert(s_wsec); + g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "none"); + g_assert_cmpint(nm_setting_wireless_security_get_wep_tx_keyidx(s_wsec), ==, 0); + + key_type = nm_setting_wireless_security_get_wep_key_type(s_wsec); + g_assert(key_type == NM_WEP_KEY_TYPE_UNKNOWN || key_type == NM_WEP_KEY_TYPE_KEY); + + g_assert_cmpstr(nm_setting_wireless_security_get_wep_key(s_wsec, 0), ==, "LoremIpsumSit"); + g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 1)); + g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 2)); + g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 3)); + + g_object_unref(connection); +} + +static void +test_read_wifi_leap(void) +{ + NMConnection * connection; + NMSettingConnection * s_con; + NMSettingWireless * s_wireless; + NMSettingWirelessSecurity *s_wsec; + + connection = + _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-leap", NULL, TYPE_WIRELESS, NULL); + + /* ===== CONNECTION SETTING ===== */ + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System blahblah (test-wifi-leap)"); + + /* ===== WIRELESS SETTING ===== */ + + s_wireless = nm_connection_get_setting_wireless(connection); + g_assert(s_wireless); + + /* ===== WIRELESS SECURITY SETTING ===== */ + + s_wsec = nm_connection_get_setting_wireless_security(connection); + g_assert(s_wsec); + g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "ieee8021x"); + g_assert_cmpstr(nm_setting_wireless_security_get_auth_alg(s_wsec), ==, "leap"); + g_assert_cmpstr(nm_setting_wireless_security_get_leap_username(s_wsec), ==, "Bill Smith"); + g_assert_cmpstr(nm_setting_wireless_security_get_leap_password(s_wsec), ==, "foobarblah"); + + g_object_unref(connection); +} + +static void +test_read_wifi_leap_secret_flags(gconstpointer test_data) +{ + NMConnection * connection; + NMSettingWireless * s_wifi; + NMSettingWirelessSecurity *s_wsec; + const char * file; + gpointer expected_flags_p; + + nmtst_test_data_unpack(test_data, &file, &expected_flags_p); + + connection = _connection_from_file(file, NULL, TYPE_WIRELESS, NULL); + + /* ===== WIRELESS SETTING ===== */ + s_wifi = nm_connection_get_setting_wireless(connection); + g_assert(s_wifi); + + /* ===== WIRELESS SECURITY SETTING ===== */ + s_wsec = nm_connection_get_setting_wireless_security(connection); + g_assert(s_wsec); + + g_assert(g_strcmp0(nm_setting_wireless_security_get_key_mgmt(s_wsec), "ieee8021x") == 0); + g_assert(g_strcmp0(nm_setting_wireless_security_get_auth_alg(s_wsec), "leap") == 0); + g_assert(g_strcmp0(nm_setting_wireless_security_get_leap_username(s_wsec), "Bill Smith") == 0); + /* password blank as it's not system-owned */ + g_assert(nm_setting_wireless_security_get_leap_password_flags(s_wsec) + == GPOINTER_TO_INT(expected_flags_p)); + g_assert(nm_setting_wireless_security_get_leap_password(s_wsec) == NULL); + + g_object_unref(connection); +} + +static void +test_ifcfg_no_trailing_newline(void) +{ + shvarFile *sv; + + sv = _svOpenFile(TEST_IFCFG_DIR "/ifcfg-test-wifi-wpa-psk"); + _svGetValue_check(sv, "CTCPROT", "no-newline"); + svCloseFile(sv); +} + +static void +test_read_wifi_wpa_psk(void) +{ + NMConnection * connection; + NMSettingConnection * s_con; + NMSettingWireless * s_wireless; + NMSettingWirelessSecurity *s_wsec; + NMSettingIPConfig * s_ip4; + GBytes * ssid; + const char * mac; + char expected_mac_address[ETH_ALEN] = {0x00, 0x16, 0x41, 0x11, 0x22, 0x33}; + const char *expected_ssid = "blahblah"; + guint32 n, i; + gboolean found_pair_tkip = FALSE; + gboolean found_pair_ccmp = FALSE; + gboolean found_group_tkip = FALSE; + gboolean found_group_ccmp = FALSE; + gboolean found_group_wep40 = FALSE; + gboolean found_group_wep104 = FALSE; + gboolean found_proto_wpa = FALSE; + gboolean found_proto_rsn = FALSE; + + connection = + _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wpa-psk", NULL, TYPE_WIRELESS, NULL); + + /* ===== CONNECTION SETTING ===== */ + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System blahblah (test-wifi-wpa-psk)"); + + /* UUID can't be tested if the ifcfg does not contain the UUID key, because + * the UUID is generated on the full path of the ifcfg file, which can change + * depending on where the tests are run. + */ + + g_assert_cmpint(nm_setting_connection_get_timestamp(s_con), ==, 0); + g_assert(nm_setting_connection_get_autoconnect(s_con)); + + /* ===== WIRELESS SETTING ===== */ + + s_wireless = nm_connection_get_setting_wireless(connection); + g_assert(s_wireless); + + mac = nm_setting_wireless_get_mac_address(s_wireless); + g_assert(mac); + g_assert(nm_utils_hwaddr_matches(mac, -1, expected_mac_address, sizeof(expected_mac_address))); + + g_assert_cmpint(nm_setting_wireless_get_mtu(s_wireless), ==, 0); + + ssid = nm_setting_wireless_get_ssid(s_wireless); + g_assert(ssid); + g_assert_cmpmem(g_bytes_get_data(ssid, NULL), + g_bytes_get_size(ssid), + expected_ssid, + strlen(expected_ssid)); + + g_assert(!nm_setting_wireless_get_bssid(s_wireless)); + g_assert_cmpstr(nm_setting_wireless_get_mode(s_wireless), ==, "infrastructure"); + g_assert_cmpint(nm_setting_wireless_get_channel(s_wireless), ==, 1); + + /* ===== WIRELESS SECURITY SETTING ===== */ + + s_wsec = nm_connection_get_setting_wireless_security(connection); + g_assert(s_wsec); + g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "wpa-psk"); + g_assert_cmpstr(nm_setting_wireless_security_get_psk(s_wsec), + ==, + "I wonder what the king is doing tonight?"); + g_assert(!nm_setting_wireless_security_get_auth_alg(s_wsec)); + + /* Pairwise ciphers */ + n = nm_setting_wireless_security_get_num_pairwise(s_wsec); + g_assert_cmpint(n, ==, 2); + for (i = 0; i < n; i++) { + const char *tmp = nm_setting_wireless_security_get_pairwise(s_wsec, i); + g_assert(tmp); + if (strcmp(tmp, "tkip") == 0) + found_pair_tkip = TRUE; + else if (strcmp(tmp, "ccmp") == 0) + found_pair_ccmp = TRUE; + } + g_assert(found_pair_tkip); + g_assert(found_pair_ccmp); + + /* Group ciphers */ + n = nm_setting_wireless_security_get_num_groups(s_wsec); + g_assert_cmpint(n, ==, 4); + for (i = 0; i < n; i++) { + const char *tmp = nm_setting_wireless_security_get_group(s_wsec, i); + g_assert(tmp); + if (strcmp(tmp, "tkip") == 0) + found_group_tkip = TRUE; + else if (strcmp(tmp, "ccmp") == 0) + found_group_ccmp = TRUE; + else if (strcmp(tmp, "wep40") == 0) + found_group_wep40 = TRUE; + else if (strcmp(tmp, "wep104") == 0) + found_group_wep104 = TRUE; + } + g_assert(found_group_tkip); + g_assert(found_group_ccmp); + g_assert(found_group_wep40); + g_assert(found_group_wep104); + + /* Protocols */ + n = nm_setting_wireless_security_get_num_protos(s_wsec); + g_assert_cmpint(n, ==, 2); + for (i = 0; i < n; i++) { + const char *tmp = nm_setting_wireless_security_get_proto(s_wsec, i); + g_assert(tmp); + if (strcmp(tmp, "wpa") == 0) + found_proto_wpa = TRUE; + else if (strcmp(tmp, "rsn") == 0) + found_proto_rsn = TRUE; + } + g_assert(found_proto_wpa); + g_assert(found_proto_rsn); + + /* ===== IPv4 SETTING ===== */ + + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); + + g_object_unref(connection); +} + +static void +test_read_wifi_sae(void) +{ + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wireless; + NMSettingWirelessSecurity * s_wsec; + GBytes * ssid; + const char * expected_ssid = "blahblah"; + + connection = + _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-sae", NULL, TYPE_WIRELESS, NULL); + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System blahblah (test-wifi-sae)"); + + g_assert_cmpint(nm_setting_connection_get_timestamp(s_con), ==, 0); + g_assert(nm_setting_connection_get_autoconnect(s_con)); + + s_wireless = nm_connection_get_setting_wireless(connection); + g_assert(s_wireless); + + g_assert_cmpint(nm_setting_wireless_get_mtu(s_wireless), ==, 0); + + ssid = nm_setting_wireless_get_ssid(s_wireless); + g_assert(ssid); + g_assert_cmpmem(g_bytes_get_data(ssid, NULL), + g_bytes_get_size(ssid), + expected_ssid, + strlen(expected_ssid)); + + g_assert(!nm_setting_wireless_get_bssid(s_wireless)); + g_assert_cmpstr(nm_setting_wireless_get_mode(s_wireless), ==, "infrastructure"); + + s_wsec = nm_connection_get_setting_wireless_security(connection); + g_assert(s_wsec); + g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "sae"); + g_assert_cmpstr(nm_setting_wireless_security_get_psk(s_wsec), ==, "The king is dead."); + g_assert(!nm_setting_wireless_security_get_auth_alg(s_wsec)); +} + +static void +test_read_wifi_owe(void) +{ + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wireless; + NMSettingWirelessSecurity * s_wsec; + GBytes * ssid; + const char * expected_ssid = "blahblah_owe"; + + connection = + _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-owe", NULL, TYPE_WIRELESS, NULL); + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System blahblah_owe (test-wifi-owe)"); + + g_assert_cmpint(nm_setting_connection_get_timestamp(s_con), ==, 0); + g_assert(nm_setting_connection_get_autoconnect(s_con)); + + s_wireless = nm_connection_get_setting_wireless(connection); + g_assert(s_wireless); + + g_assert_cmpint(nm_setting_wireless_get_mtu(s_wireless), ==, 0); + + ssid = nm_setting_wireless_get_ssid(s_wireless); + g_assert(ssid); + g_assert_cmpmem(g_bytes_get_data(ssid, NULL), + g_bytes_get_size(ssid), + expected_ssid, + strlen(expected_ssid)); + + g_assert(!nm_setting_wireless_get_bssid(s_wireless)); + g_assert_cmpstr(nm_setting_wireless_get_mode(s_wireless), ==, "infrastructure"); + + s_wsec = nm_connection_get_setting_wireless_security(connection); + g_assert(s_wsec); + g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "owe"); + g_assert(!nm_setting_wireless_security_get_psk(s_wsec)); + g_assert(!nm_setting_wireless_security_get_auth_alg(s_wsec)); +} + +static void +test_read_wifi_wpa_psk_2(void) +{ + NMConnection * connection; + NMSettingConnection * s_con; + NMSettingWireless * s_wireless; + NMSettingWirelessSecurity *s_wsec; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wpa-psk-2", + NULL, + TYPE_WIRELESS, + NULL); + + /* ===== CONNECTION SETTING ===== */ + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System ipsum (test-wifi-wpa-psk-2)"); + + /* ===== WIRELESS SETTING ===== */ + + s_wireless = nm_connection_get_setting_wireless(connection); + g_assert(s_wireless); + + /* ===== WIRELESS SECURITY SETTING ===== */ + + s_wsec = nm_connection_get_setting_wireless_security(connection); + g_assert(s_wsec); + g_assert_cmpstr(nm_setting_wireless_security_get_psk(s_wsec), + ==, + "They're really saying I love you. >>`<< '"); + + g_object_unref(connection); +} + +static void +test_read_wifi_wpa_psk_unquoted(void) +{ + NMConnection * connection; + NMSettingConnection * s_con; + NMSettingWireless * s_wireless; + NMSettingWirelessSecurity *s_wsec; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wpa-psk-unquoted", + NULL, + TYPE_WIRELESS, + NULL); + + /* ===== CONNECTION SETTING ===== */ + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), + ==, + "System blahblah (test-wifi-wpa-psk-unquoted)"); + + /* ===== WIRELESS SETTING ===== */ + + s_wireless = nm_connection_get_setting_wireless(connection); + g_assert(s_wireless); + + /* ===== WIRELESS SECURITY SETTING ===== */ + + s_wsec = nm_connection_get_setting_wireless_security(connection); + g_assert(s_wsec); + g_assert_cmpstr(nm_setting_wireless_security_get_psk(s_wsec), ==, "54336845e2f3f321c4c7"); + + g_object_unref(connection); +} + +static void +test_read_wifi_wpa_psk_unquoted2(void) +{ + gs_unref_object NMConnection *connection = NULL; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wpa-psk-unquoted2", + NULL, + TYPE_WIRELESS, + NULL); +} + +static void +test_read_wifi_wpa_psk_adhoc(void) +{ + NMConnection * connection; + NMSettingConnection * s_con; + NMSettingWireless * s_wireless; + NMSettingWirelessSecurity *s_wsec; + NMSettingIPConfig * s_ip4; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wpa-psk-adhoc", + NULL, + TYPE_WIRELESS, + NULL); + + /* ===== CONNECTION SETTING ===== */ + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), + ==, + "System blahblah (test-wifi-wpa-psk-adhoc)"); + + /* ===== WIRELESS SETTING ===== */ + + s_wireless = nm_connection_get_setting_wireless(connection); + g_assert(s_wireless); + + g_assert_cmpstr(nm_setting_wireless_get_mode(s_wireless), ==, "adhoc"); + + /* ===== WIRELESS SECURITY SETTING ===== */ + + s_wsec = nm_connection_get_setting_wireless_security(connection); + g_assert(s_wsec); + g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "wpa-psk"); + g_assert_cmpstr(nm_setting_wireless_security_get_psk(s_wsec), + ==, + "I wonder what the king is doing tonight?"); + + g_assert_cmpint(nm_setting_wireless_security_get_num_pairwise(s_wsec), ==, 1); + g_assert_cmpstr(nm_setting_wireless_security_get_pairwise(s_wsec, 0), ==, "ccmp"); + + g_assert_cmpint(nm_setting_wireless_security_get_num_groups(s_wsec), ==, 1); + g_assert_cmpstr(nm_setting_wireless_security_get_group(s_wsec, 0), ==, "ccmp"); + + g_assert_cmpint(nm_setting_wireless_security_get_num_protos(s_wsec), ==, 1); + g_assert_cmpstr(nm_setting_wireless_security_get_proto(s_wsec, 0), ==, "rsn"); + + /* ===== IPv4 SETTING ===== */ + + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); + + g_object_unref(connection); +} + +static void +test_read_wifi_wpa_psk_hex(void) +{ + NMConnection * connection; + NMSettingConnection * s_con; + NMSettingWireless * s_wireless; + NMSettingWirelessSecurity *s_wsec; + NMSettingIPConfig * s_ip4; + GBytes * ssid; + const char * expected_ssid = "blahblah"; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wpa-psk-hex", + NULL, + TYPE_WIRELESS, + NULL); + + /* ===== CONNECTION SETTING ===== */ + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), + ==, + "System blahblah (test-wifi-wpa-psk-hex)"); + + /* ===== WIRELESS SETTING ===== */ + + s_wireless = nm_connection_get_setting_wireless(connection); + g_assert(s_wireless); + + ssid = nm_setting_wireless_get_ssid(s_wireless); + g_assert(ssid); + g_assert(nm_utils_gbytes_equal_mem(ssid, expected_ssid, strlen(expected_ssid))); + + /* ===== WIRELESS SECURITY SETTING ===== */ + + s_wsec = nm_connection_get_setting_wireless_security(connection); + g_assert(s_wsec); + g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "wpa-psk"); + g_assert_cmpstr(nm_setting_wireless_security_get_psk(s_wsec), + ==, + "1da190379817bc360dda52e85c388c439a21ea5c7bf819c64e9da051807deae6"); + + /* ===== IPv4 SETTING ===== */ + + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); + + g_object_unref(connection); +} + +#define TEST_IFCFG_WIFI_WPA_EAP_TLS_CA_CERT TEST_IFCFG_DIR "/test_ca_cert.pem" +#define TEST_IFCFG_WIFI_WPA_EAP_TLS_CLIENT_CERT TEST_IFCFG_DIR "/test1_key_and_cert.pem" +#define TEST_IFCFG_WIFI_WPA_EAP_TLS_PRIVATE_KEY TEST_IFCFG_DIR "/test1_key_and_cert.pem" + +static void +test_read_wifi_wpa_eap_tls(void) +{ + NMConnection * connection; + NMSettingWireless *s_wireless; + NMSettingIPConfig *s_ip4; + NMSetting8021x * s_8021x; + char * unmanaged = NULL; + const char * expected_privkey_password = "test1"; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wpa-eap-tls", + NULL, + TYPE_ETHERNET, + &unmanaged); + g_assert(!unmanaged); + + /* ===== WIRELESS SETTING ===== */ + + s_wireless = nm_connection_get_setting_wireless(connection); + g_assert(s_wireless); + + /* ===== IPv4 SETTING ===== */ + + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); + + /* ===== 802.1x SETTING ===== */ + s_8021x = nm_connection_get_setting_802_1x(connection); + g_assert(s_8021x); + g_assert_cmpint(nm_setting_802_1x_get_num_eap_methods(s_8021x), ==, 1); + g_assert_cmpstr(nm_setting_802_1x_get_eap_method(s_8021x, 0), ==, "tls"); + g_assert_cmpstr(nm_setting_802_1x_get_identity(s_8021x), ==, "Bill Smith"); + + /* CA Cert */ + verify_cert_or_key(s_8021x, + TEST_IFCFG_WIFI_WPA_EAP_TLS_CA_CERT, + NULL, + NM_SETTING_802_1X_CA_CERT); + + /* Client Cert */ + verify_cert_or_key(s_8021x, + TEST_IFCFG_WIFI_WPA_EAP_TLS_CLIENT_CERT, + NULL, + NM_SETTING_802_1X_CLIENT_CERT); + + /* Private Key Password */ + g_assert_cmpstr(nm_setting_802_1x_get_private_key_password(s_8021x), + ==, + expected_privkey_password); + + /* Private key */ + verify_cert_or_key(s_8021x, + TEST_IFCFG_WIFI_WPA_EAP_TLS_PRIVATE_KEY, + expected_privkey_password, + NM_SETTING_802_1X_PRIVATE_KEY); + + g_object_unref(connection); +} + +/* Also use TLS defines from the previous test */ + +static void +test_read_wifi_wpa_eap_ttls_tls(void) +{ + NMConnection * connection; + NMSettingWireless *s_wireless; + NMSettingIPConfig *s_ip4; + NMSetting8021x * s_8021x; + char * unmanaged = NULL; + const char * expected_privkey_password = "test1"; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wpa-eap-ttls-tls", + NULL, + TYPE_WIRELESS, + &unmanaged); + g_assert(!unmanaged); + + /* ===== WIRELESS SETTING ===== */ + + s_wireless = nm_connection_get_setting_wireless(connection); + g_assert(s_wireless); + + /* ===== IPv4 SETTING ===== */ + + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); + + /* ===== 802.1x SETTING ===== */ + s_8021x = nm_connection_get_setting_802_1x(connection); + g_assert(s_8021x); + g_assert_cmpint(nm_setting_802_1x_get_num_eap_methods(s_8021x), ==, 1); + g_assert_cmpstr(nm_setting_802_1x_get_eap_method(s_8021x, 0), ==, "ttls"); + g_assert_cmpstr(nm_setting_802_1x_get_identity(s_8021x), ==, "Chuck Shumer"); + + /* CA Cert */ + verify_cert_or_key(s_8021x, + TEST_IFCFG_DIR "/test_ca_cert.pem", + NULL, + NM_SETTING_802_1X_CA_CERT); + + /* Inner auth method */ + g_assert_cmpstr(nm_setting_802_1x_get_phase2_autheap(s_8021x), ==, "tls"); + + /* Inner CA Cert */ + verify_cert_or_key(s_8021x, + TEST_IFCFG_WIFI_WPA_EAP_TLS_CA_CERT, + NULL, + NM_SETTING_802_1X_PHASE2_CA_CERT); + + /* Inner Client Cert */ + verify_cert_or_key(s_8021x, + TEST_IFCFG_WIFI_WPA_EAP_TLS_CLIENT_CERT, + NULL, + NM_SETTING_802_1X_PHASE2_CLIENT_CERT); + + /* Inner Private Key Password */ + g_assert_cmpstr(nm_setting_802_1x_get_phase2_private_key_password(s_8021x), + ==, + expected_privkey_password); + + /* Inner private key */ + verify_cert_or_key(s_8021x, + TEST_IFCFG_WIFI_WPA_EAP_TLS_PRIVATE_KEY, + expected_privkey_password, + NM_SETTING_802_1X_PHASE2_PRIVATE_KEY); + + g_object_unref(connection); +} + +static void +test_read_wifi_wpa_eap_suite_b_192_tls(void) +{ + NMConnection * connection; + NMSettingWireless * s_wireless; + NMSettingWirelessSecurity *s_wireless_sec; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wpa-eap-suite-b-192-tls", + NULL, + TYPE_WIRELESS, + NULL); + + /* ===== WIRELESS SETTING ===== */ + + s_wireless = nm_connection_get_setting_wireless(connection); + g_assert(s_wireless); + + /* ===== WIRELESS SECURITY SETTING ===== */ + + s_wireless_sec = nm_connection_get_setting_wireless_security(connection); + g_assert(s_wireless_sec); + g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wireless_sec), + ==, + "wpa-eap-suite-b-192"); + + g_object_unref(connection); +} + +static void +test_read_wifi_dynamic_wep_leap(void) +{ + NMConnection * connection; + NMSettingWireless * s_wifi; + NMSettingWirelessSecurity *s_wsec; + NMSetting8021x * s_8021x; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-dynamic-wep-leap", + NULL, + TYPE_WIRELESS, + NULL); + + /* ===== WIRELESS SETTING ===== */ + + s_wifi = nm_connection_get_setting_wireless(connection); + g_assert(s_wifi); + + /* ===== Wi-Fi SECURITY SETTING ===== */ + s_wsec = nm_connection_get_setting_wireless_security(connection); + g_assert(s_wsec); + + /* Key management */ + g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "ieee8021x"); + + /* Auth alg should be NULL (open) for dynamic WEP with LEAP as the EAP method; + * only "old-school" LEAP uses 'leap' for the auth alg. + */ + g_assert_cmpstr(nm_setting_wireless_security_get_auth_alg(s_wsec), ==, NULL); + + /* Expect no old-school LEAP username/password, that'll be in the 802.1x setting */ + g_assert_cmpstr(nm_setting_wireless_security_get_leap_username(s_wsec), ==, NULL); + g_assert_cmpstr(nm_setting_wireless_security_get_leap_password(s_wsec), ==, NULL); + + /* ===== 802.1x SETTING ===== */ + s_8021x = nm_connection_get_setting_802_1x(connection); + g_assert(s_8021x); + + /* EAP method should be "leap" */ + g_assert_cmpint(nm_setting_802_1x_get_num_eap_methods(s_8021x), ==, 1); + g_assert_cmpstr(nm_setting_802_1x_get_eap_method(s_8021x, 0), ==, "leap"); + + /* username & password */ + g_assert_cmpstr(nm_setting_802_1x_get_identity(s_8021x), ==, "bill smith"); + g_assert_cmpstr(nm_setting_802_1x_get_password(s_8021x), ==, "foobar baz"); + + g_object_unref(connection); +} + +static void +test_read_wifi_wep_eap_ttls_chap(void) +{ + NMConnection * connection; + NMSettingWireless * s_wireless; + NMSettingWirelessSecurity *s_wsec; + NMSettingIPConfig * s_ip4; + NMSetting8021x * s_8021x; + char * unmanaged = NULL; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wep-eap-ttls-chap", + NULL, + TYPE_WIRELESS, + &unmanaged); + g_assert(!unmanaged); + + /* ===== WIRELESS SETTING ===== */ + + s_wireless = nm_connection_get_setting_wireless(connection); + g_assert(s_wireless); + + /* ===== IPv4 SETTING ===== */ + + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); + + /* ===== 802.1x SETTING ===== */ + s_wsec = nm_connection_get_setting_wireless_security(connection); + g_assert(s_wsec); + g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "ieee8021x"); + + /* ===== 802.1x SETTING ===== */ + s_8021x = nm_connection_get_setting_802_1x(connection); + g_assert(s_8021x); + + /* EAP methods */ + g_assert_cmpint(nm_setting_802_1x_get_num_eap_methods(s_8021x), ==, 1); + g_assert_cmpstr(nm_setting_802_1x_get_eap_method(s_8021x, 0), ==, "ttls"); + + /* CA Cert */ + verify_cert_or_key(s_8021x, + TEST_IFCFG_DIR "/test_ca_cert.pem", + NULL, + NM_SETTING_802_1X_CA_CERT); + + g_assert_cmpstr(nm_setting_802_1x_get_phase2_auth(s_8021x), ==, "chap"); + g_assert_cmpstr(nm_setting_802_1x_get_identity(s_8021x), ==, "David Smith"); + g_assert_cmpstr(nm_setting_802_1x_get_password(s_8021x), ==, "foobar baz"); + + g_object_unref(connection); +} + +static void +test_read_wired_wake_on_lan(void) +{ + NMConnection * connection; + NMSettingConnection *s_con; + NMSettingWired * s_wired; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-wake-on-lan", + NULL, + TYPE_WIRELESS, + NULL); + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con), + ==, + NM_SETTING_WIRED_SETTING_NAME); + + s_wired = nm_connection_get_setting_wired(connection); + g_assert(s_wired); + g_assert_cmpint(nm_setting_wired_get_wake_on_lan(s_wired), + ==, + NM_SETTING_WIRED_WAKE_ON_LAN_ARP | NM_SETTING_WIRED_WAKE_ON_LAN_PHY + | NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC); + + g_assert_cmpstr(nm_setting_wired_get_wake_on_lan_password(s_wired), ==, "00:11:22:33:44:55"); + + g_object_unref(connection); +} + +static void +test_read_wired_auto_negotiate_off(void) +{ + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-wake-on-lan", + NULL, + TYPE_ETHERNET, + NULL); + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con), + ==, + NM_SETTING_WIRED_SETTING_NAME); + + s_wired = nm_connection_get_setting_wired(connection); + g_assert(s_wired); + + g_assert(!nm_setting_wired_get_auto_negotiate(s_wired)); + g_assert_cmpint(nm_setting_wired_get_speed(s_wired), ==, 100); + g_assert_cmpstr(nm_setting_wired_get_duplex(s_wired), ==, "full"); +} + +static void +test_read_wired_auto_negotiate_on(void) +{ + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-auto-negotiate-on", + NULL, + TYPE_ETHERNET, + NULL); + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con), + ==, + NM_SETTING_WIRED_SETTING_NAME); + + s_wired = nm_connection_get_setting_wired(connection); + g_assert(s_wired); + + g_assert(nm_setting_wired_get_auto_negotiate(s_wired)); + g_assert_cmpint(nm_setting_wired_get_speed(s_wired), ==, 0); + g_assert_cmpstr(nm_setting_wired_get_duplex(s_wired), ==, NULL); +} + +static void +test_read_wired_unknown_ethtool_opt(void) +{ + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-unknown-ethtool-opt", + NULL, + TYPE_ETHERNET, + NULL); + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con), + ==, + NM_SETTING_WIRED_SETTING_NAME); + + s_wired = nm_connection_get_setting_wired(connection); + g_assert(s_wired); + + g_assert(!nm_setting_wired_get_auto_negotiate(s_wired)); + g_assert(!nm_setting_wired_get_speed(s_wired)); + g_assert(!nm_setting_wired_get_duplex(s_wired)); + + g_assert_cmpint(nm_setting_wired_get_wake_on_lan(s_wired), + ==, + NM_SETTING_WIRED_WAKE_ON_LAN_ARP | NM_SETTING_WIRED_WAKE_ON_LAN_PHY + | NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC); + g_assert_cmpstr(nm_setting_wired_get_wake_on_lan_password(s_wired), ==, "00:11:22:33:44:55"); +} + +static void +test_read_wifi_hidden(void) +{ + NMConnection * connection; + NMSettingConnection *s_con; + NMSettingWireless * s_wifi; + + connection = + _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-hidden", NULL, TYPE_WIRELESS, NULL); + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con), + ==, + NM_SETTING_WIRELESS_SETTING_NAME); + + s_wifi = nm_connection_get_setting_wireless(connection); + g_assert(s_wifi); + g_assert(nm_setting_wireless_get_hidden(s_wifi) == TRUE); + + g_object_unref(connection); +} + +static void +test_write_wifi_hidden(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + shvarFile * f; + GBytes * ssid; + const unsigned char ssid_data[] = {0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44}; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Wi-Fi Hidden", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRELESS_SETTING_NAME, + NULL); + + /* Wifi setting */ + s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wifi)); + + ssid = g_bytes_new(ssid_data, sizeof(ssid_data)); + + g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_HIDDEN, TRUE, NULL); + + g_bytes_unref(ssid); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connec_exp(connection, + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR "/ifcfg-Test_Write_WiFi_Hidden.cexpected", + &testfile); + + f = _svOpenFile(testfile); + _svGetValue_check(f, "SSID_HIDDEN", "yes"); + svCloseFile(f); + + reread = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_read_wifi_mac_random(gconstpointer user_data) +{ + gs_unref_object NMConnection *connection = NULL; + gs_free char * path = NULL; + NMSettingWireless * s_wifi; + const char * name; + gpointer value_p; + NMSettingMacRandomization value; + + nmtst_test_data_unpack(user_data, &name, &value_p); + value = GPOINTER_TO_INT(value_p); + + path = g_strdup_printf(TEST_IFCFG_DIR "/ifcfg-test-wifi-mac-random-%s", name); + connection = _connection_from_file(path, NULL, TYPE_WIRELESS, NULL); + + s_wifi = nm_connection_get_setting_wireless(connection); + g_assert(s_wifi); + g_assert_cmpint(nm_setting_wireless_get_mac_address_randomization(s_wifi), ==, value); +} + +static void +test_write_wifi_mac_random(gconstpointer user_data) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + char * val; + shvarFile * f; + GBytes * ssid; + const unsigned char ssid_data[] = {0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44}; + const char * name, *write_expected; + gpointer value_p; + NMSettingMacRandomization value; + char cexpected[NM_STRLEN(TEST_IFCFG_DIR) + 100]; + + nmtst_test_data_unpack(user_data, &name, &value_p, &write_expected); + value = GPOINTER_TO_INT(value_p); + + g_assert(write_expected); + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + val = g_strdup_printf("Test Write Wi-Fi MAC %s", name); + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + val, + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRELESS_SETTING_NAME, + NULL); + g_free(val); + + /* Wifi setting */ + s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wifi)); + + ssid = g_bytes_new(ssid_data, sizeof(ssid_data)); + g_object_set(s_wifi, + NM_SETTING_WIRELESS_SSID, + ssid, + NM_SETTING_WIRELESS_MODE, + "infrastructure", + NM_SETTING_WIRELESS_MAC_ADDRESS_RANDOMIZATION, + value, + NULL); + g_bytes_unref(ssid); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connec_exp( + connection, + TEST_SCRATCH_DIR, + nm_sprintf_buf(cexpected, TEST_IFCFG_DIR "/ifcfg-Test_Write_WiFi_MAC_%s.cexpected", name), + &testfile); + + f = _svOpenFile(testfile); + _svGetValue_check(f, "MAC_ADDRESS_RANDOMIZATION", write_expected); + svCloseFile(f); + + reread = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_write_wired_wake_on_lan(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSettingWiredWakeOnLan wol; + char * val; + shvarFile * f; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Wired Wake-on-LAN", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRED_SETTING_NAME, + NULL); + + /* Wired setting */ + s_wired = (NMSettingWired *) nm_setting_wired_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wired)); + + wol = NM_SETTING_WIRED_WAKE_ON_LAN_MULTICAST | NM_SETTING_WIRED_WAKE_ON_LAN_UNICAST + | NM_SETTING_WIRED_WAKE_ON_LAN_MAGIC; + + g_object_set(s_wired, + NM_SETTING_WIRED_WAKE_ON_LAN, + wol, + NM_SETTING_WIRED_WAKE_ON_LAN_PASSWORD, + "00:00:00:11:22:33", + NULL); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connec_exp(connection, + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR "/ifcfg-Test_Write_Wired_Wake-on-LAN.cexpected", + &testfile); + + f = _svOpenFile(testfile); + val = svGetValueStr_cp(f, "ETHTOOL_OPTS"); + g_assert(val); + g_assert(strstr(val, "wol")); + g_assert(strstr(val, "sopass 00:00:00:11:22:33")); + g_free(val); + svCloseFile(f); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_write_wired_auto_negotiate_off(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingWired * s_wired; + char * val; + shvarFile * f; + + connection = nmtst_create_minimal_connection("Test Write Wired Auto-Negotiate", + NULL, + NM_SETTING_WIRED_SETTING_NAME, + NULL); + s_wired = nm_connection_get_setting_wired(connection); + g_object_set(s_wired, + NM_SETTING_WIRED_AUTO_NEGOTIATE, + FALSE, + NM_SETTING_WIRED_DUPLEX, + "half", + NM_SETTING_WIRED_SPEED, + 10, + NULL); + + _writer_new_connec_exp(connection, + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR "/ifcfg-Test_Write_Wired_Auto-Negotiate.cexpected", + &testfile); + + f = _svOpenFile(testfile); + val = svGetValueStr_cp(f, "ETHTOOL_OPTS"); + g_assert(val); + g_assert(strstr(val, "autoneg off")); + g_assert(strstr(val, "speed 10")); + g_assert(strstr(val, "duplex half")); + g_free(val); + svCloseFile(f); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_write_wired_auto_negotiate_on(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingWired * s_wired; + NMSettingEthtool * s_ethtool; + char * val; + shvarFile * f; + + connection = nmtst_create_minimal_connection("Test Write Wired Auto-Negotiate", + NULL, + NM_SETTING_WIRED_SETTING_NAME, + NULL); + s_wired = nm_connection_get_setting_wired(connection); + g_object_set(s_wired, NM_SETTING_WIRED_AUTO_NEGOTIATE, TRUE, NULL); + + s_ethtool = NM_SETTING_ETHTOOL(nm_setting_ethtool_new()); + nm_setting_ethtool_set_feature(s_ethtool, NM_ETHTOOL_OPTNAME_FEATURE_TX, NM_TERNARY_TRUE); + nm_setting_ethtool_set_feature(s_ethtool, NM_ETHTOOL_OPTNAME_FEATURE_RXVLAN, NM_TERNARY_FALSE); + nm_connection_add_setting(connection, NM_SETTING(s_ethtool)); + + _writer_new_connec_exp(connection, + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR "/ifcfg-test_write_wired_auto_negotiate_on.cexpected", + &testfile); + + f = _svOpenFile(testfile); + val = svGetValueStr_cp(f, "ETHTOOL_OPTS"); + g_assert(val); + g_assert(strstr(val, "autoneg on")); + g_assert(!strstr(val, "speed")); + g_assert(!strstr(val, "duplex")); + g_free(val); + svCloseFile(f); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + + nmtst_assert_connection_verifies_without_normalization(reread); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); + + s_ethtool = NM_SETTING_ETHTOOL(nm_connection_get_setting(reread, NM_TYPE_SETTING_ETHTOOL)); + g_assert(s_ethtool); + g_assert_cmpint(nm_setting_ethtool_get_feature(s_ethtool, NM_ETHTOOL_OPTNAME_FEATURE_TX), + ==, + NM_TERNARY_TRUE); + g_assert_cmpint(nm_setting_ethtool_get_feature(s_ethtool, NM_ETHTOOL_OPTNAME_FEATURE_RXVLAN), + ==, + NM_TERNARY_FALSE); + g_assert_cmpint(nm_setting_ethtool_get_feature(s_ethtool, NM_ETHTOOL_OPTNAME_FEATURE_TXVLAN), + ==, + NM_TERNARY_DEFAULT); +} + +static void +test_read_wifi_band_a(void) +{ + NMConnection * connection; + NMSettingConnection *s_con; + NMSettingWireless * s_wifi; + + connection = + _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-band-a", NULL, TYPE_WIRELESS, NULL); + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con), + ==, + NM_SETTING_WIRELESS_SETTING_NAME); + + s_wifi = nm_connection_get_setting_wireless(connection); + g_assert(s_wifi); + g_assert_cmpstr(nm_setting_wireless_get_band(s_wifi), ==, "a"); + + g_object_unref(connection); +} + +static void +test_write_wifi_band_a(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + shvarFile * f; + GBytes * ssid; + const unsigned char ssid_data[] = {0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44}; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Wi-Fi Band A", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRELESS_SETTING_NAME, + NULL); + + /* Wifi setting */ + s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wifi)); + + ssid = g_bytes_new(ssid_data, sizeof(ssid_data)); + + g_object_set(s_wifi, + NM_SETTING_WIRELESS_SSID, + ssid, + NM_SETTING_WIRELESS_MODE, + "infrastructure", + NM_SETTING_WIRELESS_BAND, + "a", + NULL); + + g_bytes_unref(ssid); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connec_exp(connection, + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR "/ifcfg-Test_Write_WiFi_Band_A.cexpected", + &testfile); + + f = _svOpenFile(testfile); + _svGetValue_check(f, "BAND", "a"); + svCloseFile(f); + + reread = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_write_wifi_ap_mode(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + gs_unref_bytes GBytes *ssid = NULL; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Wi-Fi AP Mode", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRELESS_SETTING_NAME, + NULL); + + /* Wifi setting */ + s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wifi)); + + ssid = g_bytes_new("MySSID", NM_STRLEN("MySSID")); + + g_object_set(s_wifi, + NM_SETTING_WIRELESS_SSID, + ssid, + NM_SETTING_WIRELESS_MODE, + "ap", + NM_SETTING_WIRELESS_BAND, + "a", + NM_SETTING_WIRELESS_CHANNEL, + (guint) 196, + NM_SETTING_WIRELESS_AP_ISOLATION, + NM_TERNARY_TRUE, + NULL); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connec_exp(connection, + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR "/ifcfg-Test_Write_WiFi_AP_Mode.cexpected", + &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_read_wifi_band_a_channel_mismatch(void) +{ + gs_free_error GError *error = NULL; + + _connection_from_file_fail(TEST_IFCFG_DIR "/ifcfg-test-wifi-band-a-channel-mismatch", + NULL, + TYPE_WIRELESS, + &error); + g_assert_error(error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION); +} + +static void +test_read_wifi_band_bg_channel_mismatch(void) +{ + gs_free_error GError *error = NULL; + + _connection_from_file_fail(TEST_IFCFG_DIR "/ifcfg-test-wifi-band-bg-channel-mismatch", + NULL, + TYPE_WIRELESS, + &error); + g_assert_error(error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION); +} + +static void +test_read_wired_qeth_static(void) +{ + NMConnection * connection; + NMSettingConnection *s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + char * unmanaged = NULL; + const char *const * subchannels; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-qeth-static", + NULL, + TYPE_ETHERNET, + &unmanaged); + g_assert(!unmanaged); + + /* ===== CONNECTION SETTING ===== */ + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-wired-qeth-static"); + + /* ===== WIRED SETTING ===== */ + + s_wired = nm_connection_get_setting_wired(connection); + g_assert(s_wired); + + g_assert(!nm_setting_wired_get_mac_address(s_wired)); + + /* Subchannels */ + subchannels = nm_setting_wired_get_s390_subchannels(s_wired); + g_assert(subchannels); + g_assert(subchannels[0] && subchannels[1] && subchannels[2] && !subchannels[3]); + + g_assert_cmpstr(subchannels[0], ==, "0.0.0600"); + g_assert_cmpstr(subchannels[1], ==, "0.0.0601"); + g_assert_cmpstr(subchannels[2], ==, "0.0.0602"); + + g_assert_cmpstr(nm_setting_wired_get_s390_nettype(s_wired), ==, "qeth"); + g_assert_cmpstr(nm_setting_wired_get_s390_option_by_key(s_wired, "portname"), ==, "OSAPORT"); + g_assert_cmpstr(nm_setting_wired_get_s390_option_by_key(s_wired, "portno"), ==, "0"); + g_assert_cmpstr(nm_setting_wired_get_s390_option_by_key(s_wired, "layer2"), ==, "1"); + + /* ===== IPv4 SETTING ===== */ + + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), + ==, + NM_SETTING_IP4_CONFIG_METHOD_MANUAL); + + g_object_unref(connection); +} + +static void +test_read_wired_ctc_static(void) +{ + NMConnection * connection; + NMSettingConnection *s_con; + NMSettingWired * s_wired; + char * unmanaged = NULL; + const char *const * subchannels; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-ctc-static", + NULL, + TYPE_ETHERNET, + &unmanaged); + g_assert(unmanaged == NULL); + + /* ===== CONNECTION SETTING ===== */ + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con != NULL); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), ==, "System test-wired-ctc-static"); + + /* ===== WIRED SETTING ===== */ + s_wired = nm_connection_get_setting_wired(connection); + g_assert(s_wired != NULL); + + g_assert(nm_setting_wired_get_mac_address(s_wired) == NULL); + + /* Subchannels */ + subchannels = nm_setting_wired_get_s390_subchannels(s_wired); + g_assert(subchannels != NULL); + g_assert(subchannels[0] && subchannels[1] && !subchannels[2]); + + g_assert_cmpstr(subchannels[0], ==, "0.0.1b00"); + g_assert_cmpstr(subchannels[1], ==, "0.0.1b01"); + + g_assert_cmpstr(nm_setting_wired_get_s390_nettype(s_wired), ==, "ctc"); + g_assert_cmpstr(nm_setting_wired_get_s390_option_by_key(s_wired, "ctcprot"), ==, "0"); + + g_object_unref(connection); +} + +static void +test_read_wifi_wep_no_keys(void) +{ + NMConnection * connection; + NMSettingConnection * s_con; + NMSettingWireless * s_wireless; + NMSettingWirelessSecurity *s_wsec; + NMWepKeyType key_type; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wep-no-keys", + NULL, + TYPE_WIRELESS, + NULL); + + /* ===== CONNECTION SETTING ===== */ + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_id(s_con), + ==, + "System foobar (test-wifi-wep-no-keys)"); + + /* UUID can't be tested if the ifcfg does not contain the UUID key, because + * the UUID is generated on the full path of the ifcfg file, which can change + * depending on where the tests are run. + */ + + /* ===== WIRELESS SETTING ===== */ + + s_wireless = nm_connection_get_setting_wireless(connection); + g_assert(s_wireless); + + /* ===== WIRELESS SECURITY SETTING ===== */ + + s_wsec = nm_connection_get_setting_wireless_security(connection); + g_assert(s_wsec); + + /* Key management */ + g_assert_cmpstr(nm_setting_wireless_security_get_key_mgmt(s_wsec), ==, "none"); + + /* WEP key index */ + g_assert_cmpint(nm_setting_wireless_security_get_wep_tx_keyidx(s_wsec), ==, 0); + + /* WEP key type */ + key_type = nm_setting_wireless_security_get_wep_key_type(s_wsec); + g_assert(key_type == NM_WEP_KEY_TYPE_UNKNOWN || key_type == NM_WEP_KEY_TYPE_KEY); + + /* WEP key index 0; we don't expect it to be filled */ + g_assert(!nm_setting_wireless_security_get_wep_key(s_wsec, 0)); + + g_object_unref(connection); +} + +static void +test_read_permissions(void) +{ + NMConnection * connection; + NMSettingConnection *s_con; + gboolean success; + guint32 num; + const char * tmp; + + connection = + _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-permissions", NULL, TYPE_ETHERNET, NULL); + + /* ===== CONNECTION SETTING ===== */ + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + + num = nm_setting_connection_get_num_permissions(s_con); + g_assert_cmpint(num, ==, 3); + + /* verify each permission */ + tmp = NULL; + success = nm_setting_connection_get_permission(s_con, 0, NULL, &tmp, NULL); + g_assert(success); + g_assert_cmpstr(tmp, ==, "dcbw"); + + tmp = NULL; + success = nm_setting_connection_get_permission(s_con, 1, NULL, &tmp, NULL); + g_assert(success); + g_assert_cmpstr(tmp, ==, "ssmith"); + + tmp = NULL; + success = nm_setting_connection_get_permission(s_con, 2, NULL, &tmp, NULL); + g_assert(success); + g_assert_cmpstr(tmp, ==, "johnny5"); + + g_object_unref(connection); +} + +static void +test_read_wifi_wep_agent_keys(void) +{ + NMConnection * connection; + NMSettingWireless * s_wifi; + NMSettingWirelessSecurity *s_wsec; + NMWepKeyType key_type; + NMSettingSecretFlags flags; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wifi-wep-agent-keys", + NULL, + TYPE_WIRELESS, + NULL); + + /* Ensure the connection is still marked for wifi security even though + * we don't have any WEP keys because they are agent owned. + */ + + /* ===== WIRELESS SETTING ===== */ + s_wifi = nm_connection_get_setting_wireless(connection); + g_assert(s_wifi); + + /* ===== WIRELESS SECURITY SETTING ===== */ + s_wsec = nm_connection_get_setting_wireless_security(connection); + g_assert(s_wsec); + + g_assert(strcmp(nm_setting_wireless_security_get_key_mgmt(s_wsec), "none") == 0); + g_assert(nm_setting_wireless_security_get_wep_tx_keyidx(s_wsec) == 0); + + key_type = nm_setting_wireless_security_get_wep_key_type(s_wsec); + g_assert(key_type == NM_WEP_KEY_TYPE_UNKNOWN || key_type == NM_WEP_KEY_TYPE_KEY); + + /* We don't expect WEP key0 to be filled */ + g_assert(nm_setting_wireless_security_get_wep_key(s_wsec, 0) == NULL); + + flags = nm_setting_wireless_security_get_wep_key_flags(s_wsec); + g_assert(flags & NM_SETTING_SECRET_FLAG_AGENT_OWNED); + + g_object_unref(connection); +} + +static void +test_write_wired_static(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *route6file = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4, *reread_s_ip4; + NMSettingIPConfig * s_ip6, *reread_s_ip6; + NMIPAddress * addr; + NMIPAddress * addr6; + NMIPRoute * route6; + GError * error = NULL; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Wired Static", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES, + 1, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRED_SETTING_NAME, + NULL); + + /* Wired setting */ + s_wired = (NMSettingWired *) nm_setting_wired_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wired)); + + g_object_set(s_wired, + NM_SETTING_WIRED_MAC_ADDRESS, + "31:33:33:37:be:cd", + NM_SETTING_WIRED_MTU, + (guint32) 1492, + NULL); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP4_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NM_SETTING_IP_CONFIG_GATEWAY, + "1.1.1.1", + NM_SETTING_IP_CONFIG_ROUTE_METRIC, + (gint64) 204, + NULL); + + addr = nm_ip_address_new(AF_INET, "1.1.1.3", 24, &error); + g_assert_no_error(error); + nm_setting_ip_config_add_address(s_ip4, addr); + nm_ip_address_unref(addr); + + addr = nm_ip_address_new(AF_INET, "1.1.1.5", 24, &error); + g_assert_no_error(error); + nm_setting_ip_config_add_address(s_ip4, addr); + nm_ip_address_unref(addr); + + nm_setting_ip_config_add_dns(s_ip4, "4.2.2.1"); + nm_setting_ip_config_add_dns(s_ip4, "4.2.2.2"); + + nm_setting_ip_config_add_dns_search(s_ip4, "foobar.com"); + nm_setting_ip_config_add_dns_search(s_ip4, "lab.foobar.com"); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP6_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NM_SETTING_IP_CONFIG_ROUTE_METRIC, + (gint64) 206, + NULL); + + /* Add addresses */ + addr6 = nm_ip_address_new(AF_INET6, "1003:1234:abcd::1", 11, &error); + g_assert_no_error(error); + nm_setting_ip_config_add_address(s_ip6, addr6); + nm_ip_address_unref(addr6); + + addr6 = nm_ip_address_new(AF_INET6, "2003:1234:abcd::2", 22, &error); + g_assert_no_error(error); + nm_setting_ip_config_add_address(s_ip6, addr6); + nm_ip_address_unref(addr6); + + addr6 = nm_ip_address_new(AF_INET6, "3003:1234:abcd::3", 33, &error); + g_assert_no_error(error); + nm_setting_ip_config_add_address(s_ip6, addr6); + nm_ip_address_unref(addr6); + + /* Add routes */ + route6 = nm_ip_route_new(AF_INET6, + "2222:aaaa:bbbb:cccc::", + 64, + "2222:aaaa:bbbb:cccc:dddd:eeee:5555:6666", + 99, + &error); + g_assert_no_error(error); + nm_setting_ip_config_add_route(s_ip6, route6); + nm_ip_route_unref(route6); + + route6 = nm_ip_route_new(AF_INET6, "::", 128, "2222:aaaa::9999", 1, &error); + g_assert_no_error(error); + nm_ip_route_set_attribute(route6, NM_IP_ROUTE_ATTRIBUTE_CWND, g_variant_new_uint32(100)); + nm_ip_route_set_attribute(route6, NM_IP_ROUTE_ATTRIBUTE_MTU, g_variant_new_uint32(1280)); + nm_ip_route_set_attribute(route6, NM_IP_ROUTE_ATTRIBUTE_LOCK_CWND, g_variant_new_boolean(TRUE)); + nm_ip_route_set_attribute(route6, + NM_IP_ROUTE_ATTRIBUTE_FROM, + g_variant_new_string("2222::bbbb/32")); + nm_ip_route_set_attribute(route6, NM_IP_ROUTE_ATTRIBUTE_SRC, g_variant_new_string("::42")); + nm_setting_ip_config_add_route(s_ip6, route6); + nm_ip_route_unref(route6); + + /* DNS servers */ + nm_setting_ip_config_add_dns(s_ip6, "fade:0102:0103::face"); + nm_setting_ip_config_add_dns(s_ip6, "cafe:ffff:eeee:dddd:cccc:bbbb:aaaa:feed"); + + /* DNS domains */ + nm_setting_ip_config_add_dns_search(s_ip6, "foobar6.com"); + nm_setting_ip_config_add_dns_search(s_ip6, "lab6.foobar.com"); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + route6file = utils_get_route6_path(testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + + reread_s_ip4 = nm_connection_get_setting_ip4_config(reread); + reread_s_ip6 = nm_connection_get_setting_ip6_config(reread); + + g_assert_cmpint(nm_setting_ip_config_get_route_metric(reread_s_ip4), ==, 204); + g_assert_cmpint(nm_setting_ip_config_get_route_metric(reread_s_ip6), ==, 206); + + nm_connection_add_setting(connection, nm_setting_proxy_new()); + + nmtst_assert_connection_equals(connection, FALSE, reread, FALSE); +} + +static void +test_write_wired_static_with_generic(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *route6file = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4, *reread_s_ip4; + NMSettingIPConfig * s_ip6, *reread_s_ip6; + NMIPAddress * addr; + NMIPAddress * addr6; + NMIPRoute * route6; + GError * error = NULL; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Wired Static", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_AUTOCONNECT_RETRIES, + 1, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRED_SETTING_NAME, + NULL); + + /* Wired setting */ + s_wired = (NMSettingWired *) nm_setting_wired_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wired)); + + g_object_set(s_wired, + NM_SETTING_WIRED_MAC_ADDRESS, + "31:33:33:37:be:cd", + NM_SETTING_WIRED_MTU, + (guint32) 1492, + NULL); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP4_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NM_SETTING_IP_CONFIG_GATEWAY, + "1.1.1.1", + NM_SETTING_IP_CONFIG_ROUTE_METRIC, + (gint64) 204, + NULL); + + addr = nm_ip_address_new(AF_INET, "1.1.1.3", 24, &error); + g_assert_no_error(error); + nm_setting_ip_config_add_address(s_ip4, addr); + nm_ip_address_unref(addr); + + addr = nm_ip_address_new(AF_INET, "1.1.1.5", 24, &error); + g_assert_no_error(error); + nm_setting_ip_config_add_address(s_ip4, addr); + nm_ip_address_unref(addr); + + nm_setting_ip_config_add_dns(s_ip4, "4.2.2.1"); + nm_setting_ip_config_add_dns(s_ip4, "4.2.2.2"); + + nm_setting_ip_config_add_dns_search(s_ip4, "foobar.com"); + nm_setting_ip_config_add_dns_search(s_ip4, "lab.foobar.com"); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP6_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NM_SETTING_IP_CONFIG_ROUTE_METRIC, + (gint64) 206, + NULL); + + /* Add addresses */ + addr6 = nm_ip_address_new(AF_INET6, "1003:1234:abcd::1", 11, &error); + g_assert_no_error(error); + nm_setting_ip_config_add_address(s_ip6, addr6); + nm_ip_address_unref(addr6); + + addr6 = nm_ip_address_new(AF_INET6, "2003:1234:abcd::2", 22, &error); + g_assert_no_error(error); + nm_setting_ip_config_add_address(s_ip6, addr6); + nm_ip_address_unref(addr6); + + addr6 = nm_ip_address_new(AF_INET6, "3003:1234:abcd::3", 33, &error); + g_assert_no_error(error); + nm_setting_ip_config_add_address(s_ip6, addr6); + nm_ip_address_unref(addr6); + + /* Add routes */ + route6 = nm_ip_route_new(AF_INET6, + "2222:aaaa:bbbb:cccc::", + 64, + "2222:aaaa:bbbb:cccc:dddd:eeee:5555:6666", + 99, + &error); + g_assert_no_error(error); + nm_setting_ip_config_add_route(s_ip6, route6); + nm_ip_route_unref(route6); + + route6 = nm_ip_route_new(AF_INET6, "::", 128, "2222:aaaa::9999", 1, &error); + g_assert_no_error(error); + nm_ip_route_set_attribute(route6, NM_IP_ROUTE_ATTRIBUTE_CWND, g_variant_new_uint32(100)); + nm_ip_route_set_attribute(route6, NM_IP_ROUTE_ATTRIBUTE_MTU, g_variant_new_uint32(1280)); + nm_ip_route_set_attribute(route6, NM_IP_ROUTE_ATTRIBUTE_LOCK_CWND, g_variant_new_boolean(TRUE)); + nm_ip_route_set_attribute(route6, + NM_IP_ROUTE_ATTRIBUTE_FROM, + g_variant_new_string("2222::bbbb/32")); + nm_ip_route_set_attribute(route6, NM_IP_ROUTE_ATTRIBUTE_SRC, g_variant_new_string("::42")); + nm_setting_ip_config_add_route(s_ip6, route6); + nm_ip_route_unref(route6); + + /* DNS servers */ + nm_setting_ip_config_add_dns(s_ip6, "fade:0102:0103::face"); + nm_setting_ip_config_add_dns(s_ip6, "cafe:ffff:eeee:dddd:cccc:bbbb:aaaa:feed"); + + /* DNS domains */ + nm_setting_ip_config_add_dns_search(s_ip6, "foobar6.com"); + nm_setting_ip_config_add_dns_search(s_ip6, "lab6.foobar.com"); + + nm_connection_add_setting(connection, nm_setting_generic_new()); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection_FIXME(connection, TEST_SCRATCH_DIR, &testfile); + route6file = utils_get_route6_path(testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + reread_s_ip4 = nm_connection_get_setting_ip4_config(reread); + reread_s_ip6 = nm_connection_get_setting_ip6_config(reread); + + g_assert_cmpint(nm_setting_ip_config_get_route_metric(reread_s_ip4), ==, 204); + g_assert_cmpint(nm_setting_ip_config_get_route_metric(reread_s_ip6), ==, 206); + + nm_connection_add_setting(connection, nm_setting_proxy_new()); + + { + gs_unref_hashtable GHashTable *diffs = NULL; + + g_assert(!nm_connection_diff(connection, reread, NM_SETTING_COMPARE_FLAG_EXACT, &diffs)); + g_assert(diffs); + g_assert(g_hash_table_size(diffs) == 1); + g_assert(g_hash_table_lookup(diffs, "generic")); + g_assert(!nm_connection_compare(connection, reread, NM_SETTING_COMPARE_FLAG_EXACT)); + } + g_assert(!nm_connection_get_setting(reread, NM_TYPE_SETTING_GENERIC)); + nm_connection_add_setting(reread, nm_setting_generic_new()); + { + gs_unref_hashtable GHashTable *diffs = NULL; + + g_assert(nm_connection_diff(connection, reread, NM_SETTING_COMPARE_FLAG_EXACT, &diffs)); + g_assert(!diffs); + g_assert(nm_connection_compare(connection, reread, NM_SETTING_COMPARE_FLAG_EXACT)); + } +} + +static void +test_write_wired_dhcp(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Wired DHCP", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRED_SETTING_NAME, + NULL); + + /* Wired setting */ + s_wired = (NMSettingWired *) nm_setting_wired_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wired)); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP4_CONFIG_METHOD_AUTO, + NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, + "random-client-id-00:22:33", + NM_SETTING_IP4_CONFIG_DHCP_FQDN, + "awesome.hostname", + NM_SETTING_IP_CONFIG_DHCP_HOSTNAME_FLAGS, + (guint) NM_DHCP_HOSTNAME_FLAG_FQDN_ENCODED, + NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, + TRUE, + NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, + TRUE, + NM_SETTING_IP_CONFIG_DHCP_IAID, + "2864434397", + NULL); + + nmtst_assert_connection_verifies(connection); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP6_CONFIG_METHOD_DHCP, + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, + "awesome.hostname", + NM_SETTING_IP_CONFIG_DHCP_HOSTNAME_FLAGS, + (guint) NM_DHCP_HOSTNAME_FLAG_FQDN_NO_UPDATE, + NULL); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static NMIPRoutingRule * +_ip_routing_rule_new(int addr_family, const char *str) +{ + NMIPRoutingRuleAsStringFlags flags = NM_IP_ROUTING_RULE_AS_STRING_FLAGS_NONE; + gs_free_error GError *local = NULL; + NMIPRoutingRule * rule; + + if (addr_family != AF_UNSPEC) { + if (addr_family == AF_INET) + flags = NM_IP_ROUTING_RULE_AS_STRING_FLAGS_AF_INET; + else { + g_assert(addr_family == AF_INET6); + flags = NM_IP_ROUTING_RULE_AS_STRING_FLAGS_AF_INET6; + } + } + + rule = nm_ip_routing_rule_from_string(str, + NM_IP_ROUTING_RULE_AS_STRING_FLAGS_VALIDATE | flags, + NULL, + nmtst_get_rand_bool() ? &local : NULL); + nmtst_assert_success(rule, local); + + if (addr_family != AF_UNSPEC) + g_assert_cmpint(nm_ip_routing_rule_get_addr_family(rule), ==, addr_family); + return rule; +} + +static void +_ip_routing_rule_add_to_setting(NMSettingIPConfig *s_ip, const char *str) +{ + nm_auto_unref_ip_routing_rule NMIPRoutingRule *rule = NULL; + + rule = _ip_routing_rule_new(nm_setting_ip_config_get_addr_family(s_ip), str); + nm_setting_ip_config_add_routing_rule(s_ip, rule); +} + +static void +test_write_routing_rules(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + + connection = nm_simple_connection_new(); + + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Routing Rules", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRED_SETTING_NAME, + NULL); + + s_wired = (NMSettingWired *) nm_setting_wired_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wired)); + + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL); + + _ip_routing_rule_add_to_setting(s_ip4, "pref 10 from 0.0.0.0/0 table 1"); + _ip_routing_rule_add_to_setting(s_ip4, "priority 10 to 192.167.8.0/24 table 2"); + _ip_routing_rule_add_to_setting(s_ip6, "pref 10 from ::/0 table 10"); + _ip_routing_rule_add_to_setting(s_ip6, "pref 10 from ::/0 to 1:2:3::5/24 table 22"); + _ip_routing_rule_add_to_setting(s_ip6, "pref 10 from ::/0 to 1:3:3::5/128 table 55"); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connec_exp(connection, + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR "/ifcfg-Test_Write_Routing_Rules.cexpected", + &testfile); + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_write_wired_match(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSettingMatch * s_match; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Wired with Match setting", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRED_SETTING_NAME, + NULL); + + /* Wired setting */ + s_wired = (NMSettingWired *) nm_setting_wired_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wired)); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NULL); + + /* Match setting */ + s_match = (NMSettingMatch *) nm_setting_match_new(); + nm_setting_match_add_interface_name(s_match, "ens*"); + nm_setting_match_add_interface_name(s_match, "eth 1?"); + nm_setting_match_add_interface_name(s_match, "!veth*"); + nm_setting_match_add_driver(s_match, "!virtio"); + nm_setting_match_add_driver(s_match, "e1000e"); + nm_setting_match_add_kernel_command_line(s_match, "!ip="); + nm_connection_add_setting(connection, NM_SETTING(s_match)); + + nmtst_assert_connection_verifies(connection); + _writer_new_connec_exp(connection, + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR "/ifcfg-Test_Write_Wired_match.cexpected", + &testfile); + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_write_wired_dhcp_plus_ip(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-dhcp-plus-ip", + NULL, + TYPE_ETHERNET, + NULL); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_read_write_wired_dhcp_send_hostname(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + const char * dhcp_hostname = "kamil-patka"; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-dhcp-send-hostname", + NULL, + TYPE_ETHERNET, + NULL); + + /* Check dhcp-hostname and dhcp-send-hostname */ + s_ip4 = nm_connection_get_setting_ip4_config(connection); + s_ip6 = nm_connection_get_setting_ip6_config(connection); + g_assert(s_ip4); + g_assert(s_ip6); + g_assert(nm_setting_ip_config_get_dhcp_send_hostname(s_ip4) == TRUE); + g_assert_cmpstr(nm_setting_ip_config_get_dhcp_hostname(s_ip4), ==, "svata-pulec"); + g_assert(!nm_setting_ip_config_get_dhcp_hostname(s_ip6)); + + /* Set dhcp-send-hostname=false dhcp-hostname="kamil-patka" and write the connection. */ + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_DHCP_SEND_HOSTNAME, FALSE, NULL); + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, dhcp_hostname, NULL); + g_object_set(s_ip6, NM_SETTING_IP_CONFIG_DHCP_HOSTNAME, dhcp_hostname, NULL); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); + + /* Check dhcp-hostname and dhcp-send-hostname from the re-read connection. */ + s_ip4 = nm_connection_get_setting_ip4_config(reread); + s_ip6 = nm_connection_get_setting_ip6_config(reread); + g_assert(s_ip4); + g_assert(s_ip6); + g_assert(nm_setting_ip_config_get_dhcp_send_hostname(s_ip4) == FALSE); + g_assert_cmpstr(nm_setting_ip_config_get_dhcp_hostname(s_ip4), ==, dhcp_hostname); + g_assert_cmpstr(nm_setting_ip_config_get_dhcp_hostname(s_ip6), ==, dhcp_hostname); +} + +static void +test_read_wired_dhcpv6_hostname_fallback(void) +{ + gs_unref_object NMConnection *connection = NULL; + NMSettingIPConfig * s_ip6; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-wired-dhcpv6-hostname-fallback", + NULL, + TYPE_ETHERNET, + NULL); + + s_ip6 = nm_connection_get_setting_ip6_config(connection); + g_assert(s_ip6); + g_assert(nm_setting_ip_config_get_dhcp_send_hostname(s_ip6) == TRUE); + g_assert_cmpstr(nm_setting_ip_config_get_dhcp_hostname(s_ip6), ==, "fully.qualified.domain"); +} + +static void +test_write_wired_static_ip6_only(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + NMIPAddress * addr6; + GError * error = NULL; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Wired Static IP6 Only", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRED_SETTING_NAME, + NULL); + + /* Wired setting */ + s_wired = (NMSettingWired *) nm_setting_wired_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wired)); + + g_object_set(s_wired, NM_SETTING_WIRED_MAC_ADDRESS, "31:33:33:37:be:cd", NULL); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_DISABLED, NULL); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL, NULL); + + /* Add addresses */ + addr6 = nm_ip_address_new(AF_INET6, "1003:1234:abcd::1", 11, &error); + g_assert_no_error(error); + nm_setting_ip_config_add_address(s_ip6, addr6); + nm_ip_address_unref(addr6); + + /* DNS server */ + nm_setting_ip_config_add_dns(s_ip6, "fade:0102:0103::face"); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_write_ip6_disabled(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + + connection = nmtst_create_minimal_connection("Test Write Wired Disabled IP6", + NULL, + NM_SETTING_WIRED_SETTING_NAME, + &s_con); + + s_wired = (NMSettingWired *) nm_setting_wired_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wired)); + + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_DISABLED, NULL); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connec_exp(connection, + TEST_SCRATCH_DIR_TMP, + TEST_IFCFG_DIR "/ifcfg-test-ip6-disabled.cexpected", + &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +/* Test writing an IPv6 config with varying gateway address. + * For missing gateway (::), we expect no IPV6_DEFAULTGW to be written + * to ifcfg-rh. + * + * As user_data pass the IPv6 address of the gateway as string. NULL means + * not to explicitly set the gateway in the configuration before writing it. + * That way, the gateway actually defaults to "::". + */ +static void +test_write_wired_static_ip6_only_gw(gconstpointer user_data) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + NMIPAddress * addr6; + GError * error = NULL; + char * id = NULL; + gs_free char * written_ifcfg_gateway = NULL; + const char * gateway6 = user_data; + shvarFile * ifcfg; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + id = g_strdup_printf("Test Write Wired Static IP6 Only With Gateway %s", gateway6 ?: "NULL"); + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + id, + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRED_SETTING_NAME, + NULL); + g_free(id); + + /* Wired setting */ + s_wired = (NMSettingWired *) nm_setting_wired_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wired)); + + g_object_set(s_wired, NM_SETTING_WIRED_MAC_ADDRESS, "31:33:33:37:be:cd", NULL); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_DISABLED, NULL); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP6_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_GATEWAY, + gateway6, + NULL); + + /* Add addresses */ + addr6 = nm_ip_address_new(AF_INET6, "1003:1234:abcd::1", 11, &error); + g_assert_no_error(error); + nm_setting_ip_config_add_address(s_ip6, addr6); + nm_ip_address_unref(addr6); + + /* DNS server */ + nm_setting_ip_config_add_dns(s_ip6, "fade:0102:0103::face"); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); + + ifcfg = _svOpenFile(testfile); + written_ifcfg_gateway = svGetValueStr_cp(ifcfg, "IPV6_DEFAULTGW"); + svCloseFile(ifcfg); + + /* access the gateway from the loaded connection. */ + s_ip6 = nm_connection_get_setting_ip6_config(reread); + g_assert(s_ip6 && nm_setting_ip_config_get_num_addresses(s_ip6) == 1); + addr6 = nm_setting_ip_config_get_address(s_ip6, 0); + g_assert(addr6); + + /* assert that the gateway was written and reloaded as expected */ + if (!gateway6 || !strcmp(gateway6, "::")) { + g_assert(nm_setting_ip_config_get_gateway(s_ip6) == NULL); + g_assert(written_ifcfg_gateway == NULL); + } else { + g_assert(nm_setting_ip_config_get_gateway(s_ip6) != NULL); + g_assert_cmpstr(nm_setting_ip_config_get_gateway(s_ip6), ==, gateway6); + g_assert_cmpstr(written_ifcfg_gateway, ==, gateway6); + } +} + +static void +test_read_write_static_routes_legacy(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *routefile = NULL; + gs_free char * route6file = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + const char * tmp; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-static-routes-legacy", + NULL, + TYPE_ETHERNET, + NULL); + + /* ===== CONNECTION SETTING ===== */ + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + + /* ID */ + tmp = nm_setting_connection_get_id(s_con); + g_assert(tmp); + + /* Autoconnect */ + g_assert(nm_setting_connection_get_autoconnect(s_con)); + + /* ===== WIRED SETTING ===== */ + + s_wired = nm_connection_get_setting_wired(connection); + g_assert(s_wired); + + /* ===== IPv4 SETTING ===== */ + + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(s_ip4); + g_assert_cmpstr(nm_setting_ip_config_get_method(s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO); + + g_assert(!nm_setting_ip_config_get_never_default(s_ip4)); + + /* Save the ifcfg; use a special different scratch dir to ensure that + * we can clean up after the written connection in both the original + * source tree and for 'make distcheck'. + */ + _writer_new_connec_exp(connection, + TEST_SCRATCH_DIR_TMP, + TEST_IFCFG_DIR "/ifcfg-test-static-routes-legacy.cexpected", + &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + routefile = utils_get_route_path(testfile); + route6file = utils_get_route6_path(testfile); + g_assert(!g_file_test(route6file, G_FILE_TEST_EXISTS)); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_write_wired_static_routes(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *routefile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + NMIPAddress * addr; + NMIPRoute * route; + GError * error = NULL; + gboolean reread_same = FALSE; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Wired Static Routes", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRED_SETTING_NAME, + NULL); + + /* Wired setting */ + s_wired = (NMSettingWired *) nm_setting_wired_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wired)); + + g_object_set(s_wired, + NM_SETTING_WIRED_MAC_ADDRESS, + "31:33:33:37:be:cd", + NM_SETTING_WIRED_MTU, + (guint32) 1492, + NULL); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP4_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_GATEWAY, + "1.1.1.1", + NM_SETTING_IP_CONFIG_DAD_TIMEOUT, + 400, + NULL); + + addr = nm_ip_address_new(AF_INET, "1.1.1.3", 24, &error); + g_assert_no_error(error); + nm_setting_ip_config_add_address(s_ip4, addr); + nm_ip_address_unref(addr); + + addr = nm_ip_address_new(AF_INET, "1.1.1.5", 24, &error); + g_assert_no_error(error); + nm_setting_ip_config_add_address(s_ip4, addr); + nm_ip_address_unref(addr); + + /* Write out routes */ + route = nm_ip_route_new(AF_INET, "1.2.3.0", 24, "222.173.190.239", 0, &error); + nm_ip_route_set_attribute(route, NM_IP_ROUTE_ATTRIBUTE_WINDOW, g_variant_new_uint32(3455)); + nm_ip_route_set_attribute(route, NM_IP_ROUTE_ATTRIBUTE_ONLINK, g_variant_new_boolean(TRUE)); + g_assert_no_error(error); + nm_setting_ip_config_add_route(s_ip4, route); + nm_ip_route_unref(route); + + route = nm_ip_route_new(AF_INET, "3.2.1.0", 24, "202.254.186.190", 77, &error); + nm_ip_route_set_attribute(route, NM_IP_ROUTE_ATTRIBUTE_WINDOW, g_variant_new_uint32(30000)); + nm_ip_route_set_attribute(route, NM_IP_ROUTE_ATTRIBUTE_ONLINK, g_variant_new_boolean(FALSE)); + g_assert_no_error(error); + nm_setting_ip_config_add_route(s_ip4, route); + nm_ip_route_unref(route); + + nm_setting_ip_config_add_dns(s_ip4, "4.2.2.1"); + nm_setting_ip_config_add_dns(s_ip4, "4.2.2.2"); + + nm_setting_ip_config_add_dns_search(s_ip4, "foobar.com"); + nm_setting_ip_config_add_dns_search(s_ip4, "lab.foobar.com"); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NULL); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection_reread(connection, + TEST_SCRATCH_DIR, + &testfile, + TEST_IFCFG_DIR "/ifcfg-Test_Write_Wired_Static_Routes.cexpected", + &reread, + &reread_same); + /* ifcfg does not support setting onlink=0. It gets lost during write+re-read. + * Assert that it's missing, and patch it to check whether the rest of the + * connection equals. */ + g_assert(!reread_same); + nmtst_assert_connection_verifies_without_normalization(reread); + s_ip4 = nm_connection_get_setting_ip4_config(reread); + g_assert(s_ip4); + g_assert_cmpint(nm_setting_ip_config_get_num_routes(s_ip4), ==, 2); + route = nm_setting_ip_config_get_route(s_ip4, 1); + g_assert(route); + g_assert(!nm_ip_route_get_attribute(route, NM_IP_ROUTE_ATTRIBUTE_ONLINK)); + nm_ip_route_set_attribute(route, NM_IP_ROUTE_ATTRIBUTE_ONLINK, g_variant_new_boolean(FALSE)); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); + + routefile = utils_get_route_path(testfile); +} + +static void +test_write_wired_dhcp_8021x_peap_mschapv2(void) +{ + nmtst_auto_unlinkfile char *keyfile = NULL; + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + NMSetting8021x * s_8021x; + gboolean success; + GError * error = NULL; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Wired DHCP 802.1x PEAP MSCHAPv2", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRED_SETTING_NAME, + NULL); + + /* Wired setting */ + s_wired = (NMSettingWired *) nm_setting_wired_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wired)); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NULL); + + /* 802.1x setting */ + s_8021x = (NMSetting8021x *) nm_setting_802_1x_new(); + nm_connection_add_setting(connection, NM_SETTING(s_8021x)); + + g_object_set(s_8021x, + NM_SETTING_802_1X_IDENTITY, + "Bob Saget", + NM_SETTING_802_1X_ANONYMOUS_IDENTITY, + "barney", + NM_SETTING_802_1X_PASSWORD, + "Kids, it was back in October 2008...", + NM_SETTING_802_1X_PHASE1_PEAPVER, + "1", + NM_SETTING_802_1X_PHASE1_PEAPLABEL, + "1", + NM_SETTING_802_1X_PHASE2_AUTH, + "mschapv2", + NULL); + + nm_setting_802_1x_add_eap_method(s_8021x, "peap"); + + success = nm_setting_802_1x_set_ca_cert(s_8021x, + TEST_IFCFG_WIRED_8021x_PEAP_MSCHAPV2_CA_CERT, + NM_SETTING_802_1X_CK_SCHEME_PATH, + NULL, + &error); + nmtst_assert_success(success, error); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); + + keyfile = utils_get_keys_path(testfile); +} + +static void +test_write_wired_8021x_tls(gconstpointer test_data) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_free char * keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + NMSetting8021x * s_8021x; + gboolean success; + GError * error = NULL; + NMSetting8021xCKFormat format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; + const char * pw; + char * tmp; + gpointer scheme_p, flags_p; + NMSetting8021xCKScheme scheme; + NMSettingSecretFlags flags; + + nmtst_test_data_unpack(test_data, &scheme_p, &flags_p); + scheme = GPOINTER_TO_INT(scheme_p); + flags = GPOINTER_TO_INT(flags_p); + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Wired 802.1x TLS Blobs", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRED_SETTING_NAME, + NULL); + + /* Wired setting */ + s_wired = (NMSettingWired *) nm_setting_wired_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wired)); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + g_object_set(s_ip6, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NULL); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + /* 802.1x setting */ + s_8021x = (NMSetting8021x *) nm_setting_802_1x_new(); + nm_connection_add_setting(connection, NM_SETTING(s_8021x)); + + g_object_set(s_8021x, NM_SETTING_802_1X_IDENTITY, "Bill Smith", NULL); + nm_setting_802_1x_add_eap_method(s_8021x, "tls"); + + /* CA cert */ + success = nm_setting_802_1x_set_ca_cert(s_8021x, + TEST_IFCFG_DIR "/test_ca_cert.pem", + scheme, + &format, + &error); + g_assert_no_error(error); + g_assert(success); + g_assert(format == NM_SETTING_802_1X_CK_FORMAT_X509); + + /* Client cert */ + format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; + success = nm_setting_802_1x_set_client_cert(s_8021x, + TEST_IFCFG_DIR "/test1_key_and_cert.pem", + scheme, + &format, + &error); + g_assert_no_error(error); + g_assert(success); + g_assert(format == NM_SETTING_802_1X_CK_FORMAT_X509); + + /* Private key */ + format = NM_SETTING_802_1X_CK_FORMAT_UNKNOWN; + success = nm_setting_802_1x_set_private_key(s_8021x, + TEST_IFCFG_DIR "/test1_key_and_cert.pem", + "test1", + scheme, + &format, + &error); + g_assert_no_error(error); + g_assert(success); + g_assert(format == NM_SETTING_802_1X_CK_FORMAT_RAW_KEY); + + /* Set secret flags */ + g_object_set(s_8021x, NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD_FLAGS, flags, NULL); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection_FIXME(connection, TEST_SCRATCH_DIR, &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); + + keyfile = utils_get_keys_path(testfile); + nmtst_file_unlink_if_exists(keyfile); + + /* Ensure the reread connection's certificates and private key are paths; no + * matter what scheme was used in the original connection they will be read + * back in as paths. + */ + s_8021x = nm_connection_get_setting_802_1x(reread); + g_assert(s_8021x); + g_assert_cmpint(nm_setting_802_1x_get_ca_cert_scheme(s_8021x), + ==, + NM_SETTING_802_1X_CK_SCHEME_PATH); + g_assert_cmpint(nm_setting_802_1x_get_client_cert_scheme(s_8021x), + ==, + NM_SETTING_802_1X_CK_SCHEME_PATH); + g_assert_cmpint(nm_setting_802_1x_get_private_key_scheme(s_8021x), + ==, + NM_SETTING_802_1X_CK_SCHEME_PATH); + + g_assert_cmpint(nm_setting_802_1x_get_private_key_password_flags(s_8021x), ==, flags); + pw = nm_setting_802_1x_get_private_key_password(s_8021x); + if (flags == NM_SETTING_SECRET_FLAG_NONE) { + /* Ensure the private key password is still set */ + g_assert(pw != NULL); + g_assert_cmpstr(pw, ==, "test1"); + } else { + /* If the secret isn't owned by system settings, make sure its no longer there */ + g_assert(pw == NULL); + } + + if (scheme == NM_SETTING_802_1X_CK_SCHEME_PATH) { + /* Do a direct compare if using the path scheme since then the + * certificate and key properties should be the same. If using blob + * scheme the original connection cert/key properties will be blobs + * but the re-read connection is always path scheme, so we wouldn't + * expect it to compare successfully. + */ + if (flags != NM_SETTING_SECRET_FLAG_NONE) { + /* Clear original connection's private key password because flags + * say it's not system-owned, and therefore it should not show up + * in the re-read connection. + */ + s_8021x = nm_connection_get_setting_802_1x(connection); + g_object_set(s_8021x, NM_SETTING_802_1X_PRIVATE_KEY_PASSWORD, NULL, NULL); + } + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); + } + + /* Clean up created certs and keys */ + tmp = utils_cert_path(testfile, "ca-cert", "der"); + nmtst_file_unlink_if_exists(tmp); + g_free(tmp); + + tmp = utils_cert_path(testfile, "client-cert", "der"); + nmtst_file_unlink_if_exists(tmp); + g_free(tmp); + + tmp = utils_cert_path(testfile, "private-key", "pem"); + nmtst_file_unlink_if_exists(tmp); + g_free(tmp); +} + +static void +test_write_wired_aliases(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + int num_addresses = 4; + const char * ip[] = {"1.1.1.1", "1.1.1.2", "1.1.1.3", "1.1.1.4"}; + const char * label[] = {NULL, "alias0:2", NULL, "alias0:3"}; + NMIPAddress * addr; + GError * error = NULL; + shvarFile * ifcfg; + int i, j; + + nmtst_file_unlink_if_exists(TEST_SCRATCH_ALIAS_BASE ":2"); + nmtst_file_unlink_if_exists(TEST_SCRATCH_ALIAS_BASE ":3"); + nmtst_file_unlink_if_exists(TEST_SCRATCH_ALIAS_BASE ":5"); + + connection = nm_simple_connection_new(); + g_assert(connection); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "alias0", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRED_SETTING_NAME, + NULL); + + /* Wired setting */ + s_wired = (NMSettingWired *) nm_setting_wired_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wired)); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP4_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_GATEWAY, + "1.1.1.1", + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NULL); + + for (i = 0; i < num_addresses; i++) { + addr = nm_ip_address_new(AF_INET, ip[i], 24, &error); + g_assert_no_error(error); + if (label[i]) + nm_ip_address_set_attribute(addr, + NM_IP_ADDRESS_ATTRIBUTE_LABEL, + g_variant_new_string(label[i])); + nm_setting_ip_config_add_address(s_ip4, addr); + nm_ip_address_unref(addr); + } + + nmtst_assert_connection_verifies(connection); + + /* Create some pre-existing alias files, to make sure they get overwritten / deleted. */ + ifcfg = svCreateFile(TEST_SCRATCH_ALIAS_BASE ":2"); + svSetValueStr(ifcfg, "DEVICE", "alias0:2"); + svSetValueStr(ifcfg, "IPADDR", "192.168.1.2"); + svWriteFile(ifcfg, 0644, NULL); + svCloseFile(ifcfg); + g_assert(g_file_test(TEST_SCRATCH_ALIAS_BASE ":2", G_FILE_TEST_EXISTS)); + + ifcfg = svCreateFile(TEST_SCRATCH_ALIAS_BASE ":5"); + svSetValueStr(ifcfg, "DEVICE", "alias0:5"); + svSetValueStr(ifcfg, "IPADDR", "192.168.1.5"); + svWriteFile(ifcfg, 0644, NULL); + svCloseFile(ifcfg); + g_assert(g_file_test(TEST_SCRATCH_ALIAS_BASE ":5", G_FILE_TEST_EXISTS)); + + _writer_new_connection_FIXME(connection, TEST_SCRATCH_DIR, &testfile); + + /* Re-check the alias files */ + g_assert(g_file_test(TEST_SCRATCH_ALIAS_BASE ":2", G_FILE_TEST_EXISTS)); + g_assert(g_file_test(TEST_SCRATCH_ALIAS_BASE ":3", G_FILE_TEST_EXISTS)); + g_assert(!g_file_test(TEST_SCRATCH_ALIAS_BASE ":5", G_FILE_TEST_EXISTS)); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + nmtst_file_unlink(TEST_SCRATCH_ALIAS_BASE ":2"); + nmtst_file_unlink(TEST_SCRATCH_ALIAS_BASE ":3"); + + /* nm_connection_compare() is not guaranteed to succeed, because the + * aliases get read back in essentially random order. So just + * verify the aliases manually. + */ + s_ip4 = nm_connection_get_setting_ip4_config(connection); + g_assert(nm_setting_ip_config_get_num_addresses(s_ip4) == num_addresses); + + /* Addresses */ + for (i = 0; i < num_addresses; i++) { + const char *addrstr; + + addr = nm_setting_ip_config_get_address(s_ip4, i); + g_assert(addr != NULL); + + addrstr = nm_ip_address_get_address(addr); + for (j = 0; j < num_addresses; j++) { + if (!g_strcmp0(addrstr, ip[j])) + break; + } + if (j >= num_addresses) + g_assert_not_reached(); + else { + g_assert_cmpint(nm_ip_address_get_prefix(addr), ==, 24); + if (label[j]) + g_assert_cmpstr( + g_variant_get_string( + nm_ip_address_get_attribute(addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL), + NULL), + ==, + label[j]); + else + g_assert(nm_ip_address_get_attribute(addr, NM_IP_ADDRESS_ATTRIBUTE_LABEL) == NULL); + ip[j] = NULL; + } + } + + for (i = 0; i < num_addresses; i++) + g_assert(!ip[i]); + + /* Gateway */ + g_assert_cmpstr(nm_setting_ip_config_get_gateway(s_ip4), ==, "1.1.1.1"); +} + +static void +test_write_gateway(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + GError * error = NULL; + shvarFile * f; + NMIPAddress * addr; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Static Addresses Gateway", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRED_SETTING_NAME, + NULL); + + /* Wired setting */ + s_wired = (NMSettingWired *) nm_setting_wired_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wired)); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP4_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_GATEWAY, + "1.1.1.254", + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NULL); + + addr = nm_ip_address_new(AF_INET, "1.1.1.3", 24, &error); + g_assert_no_error(error); + nm_setting_ip_config_add_address(s_ip4, addr); + nm_ip_address_unref(addr); + + addr = nm_ip_address_new(AF_INET, "2.2.2.5", 24, &error); + g_assert_no_error(error); + nm_setting_ip_config_add_address(s_ip4, addr); + nm_ip_address_unref(addr); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + + f = _svOpenFile(testfile); + _svGetValue_check(f, "IPADDR", "1.1.1.3"); + _svGetValue_check(f, "IPADDR1", "2.2.2.5"); + _svGetValue_check(f, "IPADDR0", NULL); + _svGetValue_check(f, "PREFIX", "24"); + _svGetValue_check(f, "PREFIX1", "24"); + _svGetValue_check(f, "PREFIX0", NULL); + _svGetValue_check(f, "GATEWAY", "1.1.1.254"); + _svGetValue_check(f, "GATEWAY0", NULL); + _svGetValue_check(f, "GATEWAY1", NULL); + svCloseFile(f); + + reread = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_write_wifi_open(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + GBytes * ssid; + const unsigned char ssid_data[] = {0x54, 0x65, 0x73, 0x74, 0x20, 0x53, 0x53, 0x49, 0x44}; + shvarFile * ifcfg; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Wifi Open", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRELESS_SETTING_NAME, + NULL); + + /* Wifi setting */ + s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wifi)); + + ssid = g_bytes_new(ssid_data, sizeof(ssid_data)); + + g_object_set(s_wifi, + NM_SETTING_WIRELESS_SSID, + ssid, + NM_SETTING_WIRELESS_BSSID, + "11:22:33:44:55:66", + NM_SETTING_WIRELESS_MAC_ADDRESS, + "aa:bb:cc:dd:ee:ff", + NM_SETTING_WIRELESS_MODE, + "infrastructure", + NM_SETTING_WIRELESS_BAND, + "bg", + NM_SETTING_WIRELESS_CHANNEL, + (guint32) 9, + NM_SETTING_WIRELESS_MTU, + (guint32) 1345, + NULL); + + g_bytes_unref(ssid); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NULL); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); + + ifcfg = _svOpenFile(testfile); + _svGetValue_check(ifcfg, "ESSID", "Test SSID"); + svCloseFile(ifcfg); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_write_wifi_open_hex_ssid(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + GBytes * ssid; + const unsigned char ssid_data[] = + {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd}; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Wifi Open Hex SSID", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRELESS_SETTING_NAME, + NULL); + + /* Wifi setting */ + s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wifi)); + + ssid = g_bytes_new(ssid_data, sizeof(ssid_data)); + + g_object_set(s_wifi, + NM_SETTING_WIRELESS_SSID, + ssid, + NM_SETTING_WIRELESS_MODE, + "infrastructure", + NULL); + + g_bytes_unref(ssid); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NULL); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_write_wifi_wep(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + NMSettingWirelessSecurity * s_wsec; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + GBytes * ssid; + const char * ssid_data = "blahblah"; + struct stat statbuf; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Wifi WEP", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRELESS_SETTING_NAME, + NULL); + + /* Wifi setting */ + s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wifi)); + + ssid = g_bytes_new(ssid_data, strlen(ssid_data)); + + g_object_set(s_wifi, + NM_SETTING_WIRELESS_SSID, + ssid, + NM_SETTING_WIRELESS_MODE, + "infrastructure", + NULL); + + g_bytes_unref(ssid); + + /* Wireless security setting */ + s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wsec)); + + g_object_set(s_wsec, + NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, + "none", + NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX, + 2, + NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, + "shared", + NULL); + nm_setting_wireless_security_set_wep_key(s_wsec, 0, "0123456789abcdef0123456789"); + nm_setting_wireless_security_set_wep_key(s_wsec, 1, "11111111111111111111111111"); + nm_setting_wireless_security_set_wep_key(s_wsec, 2, "aaaaaaaaaaaaaaaaaaaaaaaaaa"); + nm_setting_wireless_security_set_wep_key(s_wsec, 3, "BBBBBBBBBBBBBBBBBBBBBBBBBB"); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NULL); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); + + keyfile = utils_get_keys_path(testfile); + g_assert_cmpint(stat(keyfile, &statbuf), ==, 0); + g_assert(S_ISREG(statbuf.st_mode)); + g_assert_cmpint((statbuf.st_mode & 0077), ==, 0); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_write_wifi_wep_adhoc(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + NMSettingWirelessSecurity * s_wsec; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + GError * error = NULL; + GBytes * ssid; + const char * ssid_data = "blahblah"; + struct stat statbuf; + NMIPAddress * addr; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Wifi WEP AdHoc", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRELESS_SETTING_NAME, + NULL); + + /* Wifi setting */ + s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wifi)); + + ssid = g_bytes_new(ssid_data, strlen(ssid_data)); + + g_object_set(s_wifi, NM_SETTING_WIRELESS_SSID, ssid, NM_SETTING_WIRELESS_MODE, "adhoc", NULL); + + g_bytes_unref(ssid); + + /* Wireless security setting */ + s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wsec)); + + g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none", NULL); + nm_setting_wireless_security_set_wep_key(s_wsec, 0, "0123456789abcdef0123456789"); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP4_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_GATEWAY, + "1.1.1.1", + NULL); + + /* IP Address */ + addr = nm_ip_address_new(AF_INET, "1.1.1.3", 24, &error); + g_assert_no_error(error); + nm_setting_ip_config_add_address(s_ip4, addr); + nm_ip_address_unref(addr); + + nm_setting_ip_config_add_dns(s_ip4, "4.2.2.1"); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NULL); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); + + keyfile = utils_get_keys_path(testfile); + g_assert_cmpint(stat(keyfile, &statbuf), ==, 0); + g_assert(S_ISREG(statbuf.st_mode)); + g_assert_cmpint((statbuf.st_mode & 0077), ==, 0); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_write_wifi_wep_passphrase(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + NMSettingWirelessSecurity * s_wsec; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + GBytes * ssid; + const char * ssid_data = "blahblah"; + struct stat statbuf; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Wifi WEP Passphrase", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRELESS_SETTING_NAME, + NULL); + + /* Wifi setting */ + s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wifi)); + + ssid = g_bytes_new(ssid_data, strlen(ssid_data)); + + g_object_set(s_wifi, + NM_SETTING_WIRELESS_SSID, + ssid, + NM_SETTING_WIRELESS_MODE, + "infrastructure", + NULL); + + g_bytes_unref(ssid); + + /* Wireless security setting */ + s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wsec)); + + g_object_set(s_wsec, + NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, + "none", + NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX, + 0, + NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, + "shared", + NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, + NM_WEP_KEY_TYPE_PASSPHRASE, + NULL); + nm_setting_wireless_security_set_wep_key(s_wsec, 0, "asdfdjaslfjasd;flasjdfl;aksdf"); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NULL); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); + + keyfile = utils_get_keys_path(testfile); + g_assert_cmpint(stat(keyfile, &statbuf), ==, 0); + g_assert(S_ISREG(statbuf.st_mode)); + g_assert_cmpint((statbuf.st_mode & 0077), ==, 0); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_write_wifi_wep_40_ascii(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + NMSettingWirelessSecurity * s_wsec; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + GBytes * ssid; + const char * ssid_data = "blahblah40"; + struct stat statbuf; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Wifi WEP 40 ASCII", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRELESS_SETTING_NAME, + NULL); + + /* Wifi setting */ + s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wifi)); + + ssid = g_bytes_new(ssid_data, strlen(ssid_data)); + + g_object_set(s_wifi, + NM_SETTING_WIRELESS_SSID, + ssid, + NM_SETTING_WIRELESS_MODE, + "infrastructure", + NULL); + + g_bytes_unref(ssid); + + /* Wireless security setting */ + s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wsec)); + + g_object_set(s_wsec, + NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, + "none", + NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX, + 2, + NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, + NM_WEP_KEY_TYPE_KEY, + NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, + "shared", + NULL); + nm_setting_wireless_security_set_wep_key(s_wsec, 0, "lorem"); + nm_setting_wireless_security_set_wep_key(s_wsec, 1, "ipsum"); + nm_setting_wireless_security_set_wep_key(s_wsec, 2, "dolor"); + nm_setting_wireless_security_set_wep_key(s_wsec, 3, "donec"); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NULL); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); + + keyfile = utils_get_keys_path(testfile); + g_assert_cmpint(stat(keyfile, &statbuf), ==, 0); + g_assert(S_ISREG(statbuf.st_mode)); + g_assert_cmpint((statbuf.st_mode & 0077), ==, 0); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_write_wifi_wep_104_ascii(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + NMSettingWirelessSecurity * s_wsec; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + GBytes * ssid; + const char * ssid_data = "blahblah104"; + struct stat statbuf; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Wifi WEP 104 ASCII", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRELESS_SETTING_NAME, + NULL); + + /* Wifi setting */ + s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wifi)); + + ssid = g_bytes_new(ssid_data, strlen(ssid_data)); + + g_object_set(s_wifi, + NM_SETTING_WIRELESS_SSID, + ssid, + NM_SETTING_WIRELESS_MODE, + "infrastructure", + NULL); + + g_bytes_unref(ssid); + + /* Wireless security setting */ + s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wsec)); + + g_object_set(s_wsec, + NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, + "none", + NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX, + 0, + NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, + NM_WEP_KEY_TYPE_UNKNOWN, + NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, + "open", + NULL); + nm_setting_wireless_security_set_wep_key(s_wsec, 0, "LoremIpsumSit"); + nm_setting_wireless_security_set_wep_key(s_wsec, 1, "AlfaBetaGamma"); + nm_setting_wireless_security_set_wep_key(s_wsec, 2, "WEP-104 ASCII"); + nm_setting_wireless_security_set_wep_key(s_wsec, 3, "thisismyascii"); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NULL); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connec_exp(connection, + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR "/ifcfg-Test_Write_Wifi_WEP_104_ASCII.cexpected", + &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); + + keyfile = utils_get_keys_path(testfile); + g_assert_cmpint(stat(keyfile, &statbuf), ==, 0); + g_assert(S_ISREG(statbuf.st_mode)); + g_assert_cmpint((statbuf.st_mode & 0077), ==, 0); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_write_wifi_leap(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + NMSettingWirelessSecurity * s_wsec; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + GBytes * ssid; + const char * ssid_data = "blahblah"; + struct stat statbuf; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Wifi LEAP", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRELESS_SETTING_NAME, + NULL); + + /* Wifi setting */ + s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wifi)); + + ssid = g_bytes_new(ssid_data, strlen(ssid_data)); + + g_object_set(s_wifi, + NM_SETTING_WIRELESS_SSID, + ssid, + NM_SETTING_WIRELESS_MODE, + "infrastructure", + NULL); + + g_bytes_unref(ssid); + + /* Wireless security setting */ + s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wsec)); + + g_object_set(s_wsec, + NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, + "ieee8021x", + NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, + "leap", + NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME, + "Bill Smith", + NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD, + "foobar22", + NULL); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NULL); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connec_exp(connection, + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR "/ifcfg-Test_Write_Wifi_LEAP.cexpected", + &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); + + keyfile = utils_get_keys_path(testfile); + g_assert_cmpint(stat(keyfile, &statbuf), ==, 0); + g_assert(S_ISREG(statbuf.st_mode)); + g_assert_cmpint((statbuf.st_mode & 0077), ==, 0); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_write_wifi_leap_secret_flags(gconstpointer data) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_free char * keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + NMSettingWirelessSecurity * s_wsec; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + GBytes * ssid; + const char * ssid_data = "blahblah"; + NMSettingSecretFlags flags = GPOINTER_TO_UINT(data); + + connection = nm_simple_connection_new(); + g_assert(connection); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Wifi LEAP Secret Flags", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRELESS_SETTING_NAME, + NULL); + + /* Wifi setting */ + s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wifi)); + + ssid = g_bytes_new(ssid_data, strlen(ssid_data)); + g_object_set(s_wifi, + NM_SETTING_WIRELESS_SSID, + ssid, + NM_SETTING_WIRELESS_MODE, + "infrastructure", + NULL); + g_bytes_unref(ssid); + + /* Wireless security setting */ + s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wsec)); + + g_object_set(s_wsec, + NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, + "ieee8021x", + NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, + "leap", + NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME, + "Bill Smith", + NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD, + "foobar22", + NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS, + flags, + NULL); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NULL); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection_FIXME(connection, TEST_SCRATCH_DIR, &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); + + /* No key should be written out since the secret is not system owned */ + keyfile = utils_get_keys_path(testfile); + g_assert(g_file_test(keyfile, G_FILE_TEST_EXISTS) == FALSE); + + /* Remove the LEAP password from the original connection since it wont' be + * in the reread connection, as the password is not system owned. + */ + g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD, NULL, NULL); + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_write_wifi_wpa_psk(gconstpointer test_data) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + NMSettingWirelessSecurity * s_wsec; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + GBytes * ssid; + const char * ssid_data = "blahblah"; + struct { + const char *name, *psk; + gpointer wep_group_p, wpa_p, wpa2_p; + } args; + + nmtst_test_data_unpack(test_data, + &args.name, + &args.wep_group_p, + &args.wpa_p, + &args.wpa2_p, + &args.psk); + + g_assert(args.psk); + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + args.name, + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRELESS_SETTING_NAME, + NULL); + + /* Wifi setting */ + s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wifi)); + + ssid = g_bytes_new(ssid_data, strlen(ssid_data)); + + g_object_set(s_wifi, + NM_SETTING_WIRELESS_SSID, + ssid, + NM_SETTING_WIRELESS_MODE, + "infrastructure", + NULL); + + g_bytes_unref(ssid); + + /* Wireless security setting */ + s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wsec)); + + g_object_set(s_wsec, + NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, + "wpa-psk", + NM_SETTING_WIRELESS_SECURITY_PSK, + args.psk, + NM_SETTING_WIRELESS_SECURITY_PMF, + (int) NM_SETTING_WIRELESS_SECURITY_PMF_REQUIRED, + NULL); + + if (GPOINTER_TO_INT(args.wep_group_p)) { + nm_setting_wireless_security_add_group(s_wsec, "wep40"); + nm_setting_wireless_security_add_group(s_wsec, "wep104"); + } + if (GPOINTER_TO_INT(args.wpa_p)) { + nm_setting_wireless_security_add_proto(s_wsec, "wpa"); + nm_setting_wireless_security_add_pairwise(s_wsec, "tkip"); + nm_setting_wireless_security_add_group(s_wsec, "tkip"); + } + if (GPOINTER_TO_INT(args.wpa2_p)) { + nm_setting_wireless_security_add_proto(s_wsec, "rsn"); + nm_setting_wireless_security_add_pairwise(s_wsec, "ccmp"); + nm_setting_wireless_security_add_group(s_wsec, "ccmp"); + } + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NULL); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); + + keyfile = utils_get_keys_path(testfile); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_write_wifi_wpa_psk_adhoc(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + NMSettingWirelessSecurity * s_wsec; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + GError * error = NULL; + GBytes * ssid; + const char * ssid_data = "blahblah"; + NMIPAddress * addr; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Wifi WPA PSK", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRELESS_SETTING_NAME, + NULL); + + /* Wifi setting */ + s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wifi)); + + ssid = g_bytes_new(ssid_data, strlen(ssid_data)); + + g_object_set(s_wifi, + NM_SETTING_WIRELESS_SSID, + ssid, + NM_SETTING_WIRELESS_MODE, + "adhoc", + NM_SETTING_WIRELESS_CHANNEL, + 11, + NM_SETTING_WIRELESS_BAND, + "bg", + NULL); + + g_bytes_unref(ssid); + + /* Wireless security setting */ + s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wsec)); + + g_object_set(s_wsec, + NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, + "wpa-psk", + NM_SETTING_WIRELESS_SECURITY_PSK, + "7d308b11df1b4243b0f78e5f3fc68cdbb9a264ed0edf4c188edf329ff5b467f0", + NULL); + + nm_setting_wireless_security_add_proto(s_wsec, "rsn"); + nm_setting_wireless_security_add_pairwise(s_wsec, "ccmp"); + nm_setting_wireless_security_add_group(s_wsec, "ccmp"); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP4_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_GATEWAY, + "1.1.1.1", + NULL); + + /* IP Address */ + addr = nm_ip_address_new(AF_INET, "1.1.1.3", 25, &error); + g_assert_no_error(error); + nm_setting_ip_config_add_address(s_ip4, addr); + nm_ip_address_unref(addr); + + nm_setting_ip_config_add_dns(s_ip4, "4.2.2.1"); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NULL); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); + + keyfile = utils_get_keys_path(testfile); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_write_wifi_wpa_eap_tls(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + NMSettingWirelessSecurity * s_wsec; + NMSetting8021x * s_8021x; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + gboolean success; + GError * error = NULL; + GBytes * ssid; + const char * ssid_data = "blahblah"; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Wifi WPA EAP-TLS", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRELESS_SETTING_NAME, + NULL); + + /* Wifi setting */ + s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wifi)); + + ssid = g_bytes_new(ssid_data, strlen(ssid_data)); + + g_object_set(s_wifi, + NM_SETTING_WIRELESS_SSID, + ssid, + NM_SETTING_WIRELESS_MODE, + "infrastructure", + NULL); + + g_bytes_unref(ssid); + + /* Wireless security setting */ + s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wsec)); + + g_object_set(s_wsec, + NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, + "wpa-eap", + NM_SETTING_WIRELESS_SECURITY_FILS, + (int) NM_SETTING_WIRELESS_SECURITY_FILS_REQUIRED, + NULL); + nm_setting_wireless_security_add_proto(s_wsec, "wpa"); + nm_setting_wireless_security_add_pairwise(s_wsec, "tkip"); + nm_setting_wireless_security_add_group(s_wsec, "tkip"); + + /* Wireless security setting */ + s_8021x = (NMSetting8021x *) nm_setting_802_1x_new(); + nm_connection_add_setting(connection, NM_SETTING(s_8021x)); + + g_object_set(s_8021x, NM_SETTING_802_1X_IDENTITY, "Bill Smith", NULL); + g_object_set(s_8021x, + NM_SETTING_802_1X_PHASE1_AUTH_FLAGS, + (guint)(NM_SETTING_802_1X_AUTH_FLAGS_TLS_1_0_DISABLE + | NM_SETTING_802_1X_AUTH_FLAGS_TLS_1_1_DISABLE), + NULL); + + nm_setting_802_1x_add_eap_method(s_8021x, "tls"); + + success = nm_setting_802_1x_set_ca_cert(s_8021x, + TEST_IFCFG_WIFI_WPA_EAP_TLS_CA_CERT, + NM_SETTING_802_1X_CK_SCHEME_PATH, + NULL, + &error); + nmtst_assert_success(success, error); + + success = nm_setting_802_1x_set_client_cert(s_8021x, + TEST_IFCFG_WIFI_WPA_EAP_TLS_CLIENT_CERT, + NM_SETTING_802_1X_CK_SCHEME_PATH, + NULL, + &error); + nmtst_assert_success(success, error); + + success = nm_setting_802_1x_set_private_key(s_8021x, + TEST_IFCFG_WIFI_WPA_EAP_TLS_PRIVATE_KEY, + "test1", + NM_SETTING_802_1X_CK_SCHEME_PATH, + NULL, + &error); + nmtst_assert_success(success, error); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NULL); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); + + keyfile = utils_get_keys_path(testfile); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_write_wifi_wpa_eap_ttls_tls(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + NMSettingWirelessSecurity * s_wsec; + NMSetting8021x * s_8021x; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + gboolean success; + GError * error = NULL; + GBytes * ssid; + const char * ssid_data = "blahblah"; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Wifi WPA EAP-TTLS (TLS)", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRELESS_SETTING_NAME, + NULL); + + /* Wifi setting */ + s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wifi)); + + ssid = g_bytes_new(ssid_data, strlen(ssid_data)); + + g_object_set(s_wifi, + NM_SETTING_WIRELESS_SSID, + ssid, + NM_SETTING_WIRELESS_MODE, + "infrastructure", + NULL); + + g_bytes_unref(ssid); + + /* Wireless security setting */ + s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wsec)); + + g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-eap", NULL); + nm_setting_wireless_security_add_proto(s_wsec, "rsn"); + nm_setting_wireless_security_add_pairwise(s_wsec, "ccmp"); + nm_setting_wireless_security_add_group(s_wsec, "ccmp"); + + /* Wireless security setting */ + s_8021x = (NMSetting8021x *) nm_setting_802_1x_new(); + nm_connection_add_setting(connection, NM_SETTING(s_8021x)); + + nm_setting_802_1x_add_eap_method(s_8021x, "ttls"); + + g_object_set(s_8021x, + NM_SETTING_802_1X_IDENTITY, + "Bill Smith", + NM_SETTING_802_1X_ANONYMOUS_IDENTITY, + "foobar22", + NM_SETTING_802_1X_PHASE2_AUTHEAP, + "tls", + NULL); + + success = nm_setting_802_1x_set_ca_cert(s_8021x, + TEST_IFCFG_WIFI_WPA_EAP_TLS_CA_CERT, + NM_SETTING_802_1X_CK_SCHEME_PATH, + NULL, + &error); + nmtst_assert_success(success, error); + + /* Phase 2 TLS stuff */ + + /* phase2 CA cert */ + success = nm_setting_802_1x_set_phase2_ca_cert(s_8021x, + TEST_IFCFG_WIFI_WPA_EAP_TLS_CA_CERT, + NM_SETTING_802_1X_CK_SCHEME_PATH, + NULL, + &error); + nmtst_assert_success(success, error); + + /* phase2 client cert */ + success = nm_setting_802_1x_set_phase2_client_cert(s_8021x, + TEST_IFCFG_WIFI_WPA_EAP_TLS_CLIENT_CERT, + NM_SETTING_802_1X_CK_SCHEME_PATH, + NULL, + &error); + nmtst_assert_success(success, error); + + /* phase2 private key */ + success = nm_setting_802_1x_set_phase2_private_key(s_8021x, + TEST_IFCFG_WIFI_WPA_EAP_TLS_PRIVATE_KEY, + "test1", + NM_SETTING_802_1X_CK_SCHEME_PATH, + NULL, + &error); + nmtst_assert_success(success, error); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NULL); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); + + keyfile = utils_get_keys_path(testfile); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_write_wifi_wpa_eap_ttls_mschapv2(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + NMSettingWirelessSecurity * s_wsec; + NMSetting8021x * s_8021x; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + gboolean success; + GError * error = NULL; + GBytes * ssid; + const char * ssid_data = "blahblah"; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Wifi WPA EAP-TTLS (MSCHAPv2)", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRELESS_SETTING_NAME, + NULL); + + /* Wifi setting */ + s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wifi)); + + ssid = g_bytes_new(ssid_data, strlen(ssid_data)); + + g_object_set(s_wifi, + NM_SETTING_WIRELESS_SSID, + ssid, + NM_SETTING_WIRELESS_MODE, + "infrastructure", + NULL); + + g_bytes_unref(ssid); + + /* Wireless security setting */ + s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wsec)); + + g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "wpa-eap", NULL); + nm_setting_wireless_security_add_proto(s_wsec, "wpa"); + nm_setting_wireless_security_add_proto(s_wsec, "rsn"); + nm_setting_wireless_security_add_pairwise(s_wsec, "tkip"); + nm_setting_wireless_security_add_pairwise(s_wsec, "ccmp"); + nm_setting_wireless_security_add_group(s_wsec, "tkip"); + nm_setting_wireless_security_add_group(s_wsec, "ccmp"); + + /* Wireless security setting */ + s_8021x = (NMSetting8021x *) nm_setting_802_1x_new(); + nm_connection_add_setting(connection, NM_SETTING(s_8021x)); + + nm_setting_802_1x_add_eap_method(s_8021x, "ttls"); + + g_object_set(s_8021x, + NM_SETTING_802_1X_IDENTITY, + "Bill Smith", + NM_SETTING_802_1X_PASSWORD, + ";alkdfja;dslkfjsad;lkfjsadf", + NM_SETTING_802_1X_ANONYMOUS_IDENTITY, + "foobar22", + NM_SETTING_802_1X_PHASE2_AUTHEAP, + "mschapv2", + NULL); + + success = nm_setting_802_1x_set_ca_cert(s_8021x, + TEST_IFCFG_WIFI_WPA_EAP_TLS_CA_CERT, + NM_SETTING_802_1X_CK_SCHEME_PATH, + NULL, + &error); + nmtst_assert_success(success, error); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NULL); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); + + keyfile = utils_get_keys_path(testfile); +} + +static void +test_write_wifi_wpa_then_open(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_free char * keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + NMSettingWirelessSecurity * s_wsec; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + GBytes * ssid; + const char * ssid_data = "blahblah"; + + /* Test that writing out a WPA config then changing that to an open + * config doesn't leave various WPA-related keys lying around in the ifcfg. + */ + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "random wifi connection", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRELESS_SETTING_NAME, + NULL); + + /* Wifi setting */ + s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wifi)); + + ssid = g_bytes_new(ssid_data, strlen(ssid_data)); + + g_object_set(s_wifi, + NM_SETTING_WIRELESS_SSID, + ssid, + NM_SETTING_WIRELESS_MODE, + "infrastructure", + NULL); + + g_bytes_unref(ssid); + + /* Wireless security setting */ + s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wsec)); + + g_object_set(s_wsec, + NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, + "wpa-psk", + NM_SETTING_WIRELESS_SECURITY_PSK, + "some cool PSK", + NULL); + + nm_setting_wireless_security_add_proto(s_wsec, "wpa"); + nm_setting_wireless_security_add_pairwise(s_wsec, "tkip"); + nm_setting_wireless_security_add_group(s_wsec, "tkip"); + + nm_setting_wireless_security_add_proto(s_wsec, "rsn"); + nm_setting_wireless_security_add_pairwise(s_wsec, "ccmp"); + nm_setting_wireless_security_add_group(s_wsec, "ccmp"); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + g_object_set(s_ip6, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NULL); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); + + g_object_unref(reread); + + nmtst_connection_normalize(connection); + + /* Now change the connection to open and recheck */ + nm_connection_remove_setting(connection, NM_TYPE_SETTING_WIRELESS_SECURITY); + + /* Write it back out */ + _writer_update_connection(connection, + TEST_SCRATCH_DIR, + testfile, + TEST_IFCFG_DIR "/ifcfg-random_wifi_connection.cexpected"); + keyfile = utils_get_keys_path(testfile); + g_assert(!g_file_test(keyfile, G_FILE_TEST_EXISTS)); + + reread = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_write_wifi_wpa_then_wep_with_perms(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + NMSettingWirelessSecurity * s_wsec; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + gboolean success; + GBytes * ssid; + char ** perms; + const char * ssid_data = "SomeSSID"; + + /* Test that writing out a WPA config then changing that to a WEP + * config works and doesn't cause infinite loop or other issues. + */ + + connection = nm_simple_connection_new(); + g_assert(connection); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + perms = g_strsplit("user:superman:", ",", -1); + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "random wifi connection 2", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_PERMISSIONS, + perms, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRELESS_SETTING_NAME, + NULL); + g_strfreev(perms); + g_assert_cmpint(nm_setting_connection_get_num_permissions(s_con), ==, 1); + + /* Wifi setting */ + s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wifi)); + + ssid = g_bytes_new(ssid_data, strlen(ssid_data)); + + g_object_set(s_wifi, + NM_SETTING_WIRELESS_SSID, + ssid, + NM_SETTING_WIRELESS_MODE, + "infrastructure", + NULL); + + g_bytes_unref(ssid); + + /* Wireless security setting */ + s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wsec)); + + g_object_set(s_wsec, + NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, + "wpa-psk", + NM_SETTING_WIRELESS_SECURITY_PSK, + "My cool PSK", + NULL); + + nm_setting_wireless_security_add_proto(s_wsec, "wpa"); + nm_setting_wireless_security_add_pairwise(s_wsec, "tkip"); + nm_setting_wireless_security_add_group(s_wsec, "tkip"); + + nm_setting_wireless_security_add_proto(s_wsec, "rsn"); + nm_setting_wireless_security_add_pairwise(s_wsec, "ccmp"); + nm_setting_wireless_security_add_group(s_wsec, "ccmp"); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NULL); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); + + g_object_unref(reread); + + nmtst_connection_normalize(connection); + + /* Now change the connection to WEP and recheck */ + s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wsec)); + + g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "none", NULL); + nm_setting_wireless_security_set_wep_key(s_wsec, 0, "abraka dabra"); + + /* Write it back out */ + _writer_update_connection(connection, + TEST_SCRATCH_DIR, + testfile, + TEST_IFCFG_DIR "/ifcfg-random_wifi_connection_2.cexpected"); + + reread = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); + + nmtst_connection_normalize(connection); + success = nm_connection_compare(connection, + reread, + NM_SETTING_COMPARE_FLAG_IGNORE_AGENT_OWNED_SECRETS + | NM_SETTING_COMPARE_FLAG_IGNORE_NOT_SAVED_SECRETS); + g_assert(success); + + keyfile = utils_get_keys_path(testfile); +} + +static void +test_write_wifi_dynamic_wep_leap(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + nmtst_auto_unlinkfile char *keyfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + NMSettingWirelessSecurity * s_wsec; + NMSetting8021x * s_8021x; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + GBytes * ssid; + const char * ssid_data = "blahblah"; + shvarFile * ifcfg; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Wifi Dynamic WEP LEAP", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRELESS_SETTING_NAME, + NULL); + + /* Wifi setting */ + s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wifi)); + + ssid = g_bytes_new(ssid_data, strlen(ssid_data)); + + g_object_set(s_wifi, + NM_SETTING_WIRELESS_SSID, + ssid, + NM_SETTING_WIRELESS_MODE, + "infrastructure", + NULL); + + g_bytes_unref(ssid); + + /* Wireless security setting */ + s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wsec)); + + g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "ieee8021x", NULL); + + /* Wireless security setting */ + s_8021x = (NMSetting8021x *) nm_setting_802_1x_new(); + nm_connection_add_setting(connection, NM_SETTING(s_8021x)); + + nm_setting_802_1x_add_eap_method(s_8021x, "leap"); + + g_object_set(s_8021x, + NM_SETTING_802_1X_IDENTITY, + "Bill Smith", + NM_SETTING_802_1X_PASSWORD, + ";alkdfja;dslkfjsad;lkfjsadf", + NULL); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NULL); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); + + keyfile = utils_get_keys_path(testfile); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); + + /* Check and make sure that an "old-school" LEAP (Network EAP) connection + * did not get written. Check first that the auth alg is not set to "LEAP" + * and next that the only IEEE 802.1x EAP method is "LEAP". + */ + ifcfg = _svOpenFile(testfile); + _svGetValue_check(ifcfg, "SECURITYMODE", NULL); + _svGetValue_check(ifcfg, "IEEE_8021X_EAP_METHODS", "LEAP"); + svCloseFile(ifcfg); +} + +static void +test_write_wired_qeth_dhcp(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + char ** subchans; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Wired qeth Static", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRED_SETTING_NAME, + NULL); + + /* Wired setting */ + s_wired = (NMSettingWired *) nm_setting_wired_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wired)); + + subchans = g_strsplit("0.0.600,0.0.601,0.0.602", ",", -1); + g_object_set(s_wired, + NM_SETTING_WIRED_S390_SUBCHANNELS, + subchans, + NM_SETTING_WIRED_S390_NETTYPE, + "qeth", + NULL); + g_strfreev(subchans); + + nm_setting_wired_add_s390_option(s_wired, "portname", "FOOBAR"); + nm_setting_wired_add_s390_option(s_wired, "portno", "1"); + nm_setting_wired_add_s390_option(s_wired, "layer2", "0"); + nm_setting_wired_add_s390_option(s_wired, "protocol", "blahbalh"); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NULL); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_write_wired_ctc_dhcp(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + char ** subchans; + shvarFile * ifcfg; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Wired ctc Static", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRED_SETTING_NAME, + NULL); + + /* Wired setting */ + s_wired = (NMSettingWired *) nm_setting_wired_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wired)); + + subchans = g_strsplit("0.0.600,0.0.601", ",", -1); + g_object_set(s_wired, + NM_SETTING_WIRED_S390_SUBCHANNELS, + subchans, + NM_SETTING_WIRED_S390_NETTYPE, + "ctc", + NULL); + g_strfreev(subchans); + nm_setting_wired_add_s390_option(s_wired, "ctcprot", "0"); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NULL); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + + /* Ensure the CTCPROT item gets written out as its own option */ + ifcfg = _svOpenFile(testfile); + + _svGetValue_check(ifcfg, "CTCPROT", "0"); + + /* And that it's not in the generic OPTIONS string */ + _svGetValue_check(ifcfg, "OPTIONS", NULL); + + svCloseFile(ifcfg); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_write_permissions(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Permissions", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRED_SETTING_NAME, + NULL); + + nm_setting_connection_add_permission(s_con, "user", "blahblah", NULL); + nm_setting_connection_add_permission(s_con, "user", "foobar", NULL); + nm_setting_connection_add_permission(s_con, "user", "asdfasdf", NULL); + + /* Wired setting */ + s_wired = (NMSettingWired *) nm_setting_wired_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wired)); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NULL); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connec_exp(connection, + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR "/ifcfg-Test_Write_Permissions.cexpected", + &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_write_wifi_wep_agent_keys(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWireless * s_wifi; + NMSettingWirelessSecurity * s_wsec; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + const char * str_ssid = "foobarbaz"; + GBytes * ssid; + + connection = nm_simple_connection_new(); + g_assert(connection != NULL); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Wifi WEP Agent Owned", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRELESS_SETTING_NAME, + NULL); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP6_CONFIG_METHOD_IGNORE, + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NULL); + + /* Wifi setting */ + s_wifi = (NMSettingWireless *) nm_setting_wireless_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wifi)); + + ssid = g_bytes_new(str_ssid, strlen(str_ssid)); + g_object_set(s_wifi, + NM_SETTING_WIRELESS_SSID, + ssid, + NM_SETTING_WIRELESS_MODE, + "infrastructure", + NULL); + g_bytes_unref(ssid); + + /* Wifi security setting */ + s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wsec)); + + g_object_set(s_wsec, + NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, + "none", + NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, + NM_WEP_KEY_TYPE_PASSPHRASE, + NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS, + NM_SETTING_SECRET_FLAG_AGENT_OWNED, + NULL); + nm_setting_wireless_security_set_wep_key(s_wsec, 0, "asdfdjaslfjasd;flasjdfl;aksdf"); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection_FIXME(connection, TEST_SCRATCH_DIR, &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_WIRELESS, NULL); + + /* Remove the WEP key from the original, because it should not have been + * written out to disk as it was agent-owned. The new connection should + * not have any WEP keys set. + * Also the new connection should not have WEP key type set. + */ + nm_setting_wireless_security_set_wep_key(s_wsec, 0, NULL); + g_object_set(s_wsec, NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE, NM_WEP_KEY_TYPE_UNKNOWN, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_write_wired_pppoe(void) +{ + NMConnection * connection; + NMSettingConnection *s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + NMSettingPppoe * s_pppoe; + NMSettingPpp * s_ppp; + GError * error = NULL; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Wired PPPoE", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRED_SETTING_NAME, + NULL); + + /* Wired setting */ + s_wired = (NMSettingWired *) nm_setting_wired_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wired)); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + + /* PPPoE setting */ + s_pppoe = (NMSettingPppoe *) nm_setting_pppoe_new(); + nm_connection_add_setting(connection, NM_SETTING(s_pppoe)); + + g_object_set(G_OBJECT(s_pppoe), + NM_SETTING_PPPOE_SERVICE, + "stupid-service", + NM_SETTING_PPPOE_USERNAME, + "Bill Smith", + NM_SETTING_PPPOE_PASSWORD, + "test1", + NULL); + + /* PPP setting */ + s_ppp = (NMSettingPpp *) nm_setting_ppp_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ppp)); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection_fail(connection, TEST_SCRATCH_DIR, NULL); + + g_object_unref(connection); + g_clear_error(&error); +} + +static void +test_write_vpn(void) +{ + NMConnection * connection; + NMSettingConnection *s_con; + NMSettingIPConfig * s_ip4; + NMSettingVpn * s_vpn; + GError * error = NULL; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write VPN", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_VPN_SETTING_NAME, + NULL); + + /* VPN setting */ + s_vpn = (NMSettingVpn *) nm_setting_vpn_new(); + nm_connection_add_setting(connection, NM_SETTING(s_vpn)); + + g_object_set(s_vpn, + NM_SETTING_VPN_SERVICE_TYPE, + "awesomevpn", + NM_SETTING_VPN_USER_NAME, + "Bill Smith", + NULL); + + nm_setting_vpn_add_data_item(s_vpn, "server", "vpn.somewhere.com"); + nm_setting_vpn_add_secret(s_vpn, "password", "sup3rs3cr3t"); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection_fail(connection, TEST_SCRATCH_DIR, NULL); + + g_object_unref(connection); + g_clear_error(&error); +} + +static void +test_write_mobile_broadband(gconstpointer data) +{ + NMConnection * connection; + NMSettingConnection *s_con; + NMSettingIPConfig * s_ip4; + NMSettingGsm * s_gsm; + NMSettingCdma * s_cdma; + NMSettingPpp * s_ppp; + NMSettingSerial * s_serial; + GError * error = NULL; + gboolean gsm = GPOINTER_TO_UINT(data); + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + gsm ? "Test Write GSM" : "Test Write CDMA", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_TYPE, + gsm ? NM_SETTING_GSM_SETTING_NAME : NM_SETTING_CDMA_SETTING_NAME, + NULL); + + if (gsm) { + /* GSM setting */ + s_gsm = (NMSettingGsm *) nm_setting_gsm_new(); + nm_connection_add_setting(connection, NM_SETTING(s_gsm)); + } else { + /* CDMA setting */ + s_cdma = (NMSettingCdma *) nm_setting_cdma_new(); + nm_connection_add_setting(connection, NM_SETTING(s_cdma)); + + g_object_set(s_cdma, NM_SETTING_CDMA_NUMBER, "#777", NULL); + } + + /* Serial setting */ + s_serial = (NMSettingSerial *) nm_setting_serial_new(); + nm_connection_add_setting(connection, NM_SETTING(s_serial)); + + g_object_set(s_serial, + NM_SETTING_SERIAL_BAUD, + 115200, + NM_SETTING_SERIAL_BITS, + 8, + NM_SETTING_SERIAL_PARITY, + NM_SETTING_SERIAL_PARITY_NONE, + NM_SETTING_SERIAL_STOPBITS, + 1, + NULL); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + + /* PPP setting */ + s_ppp = (NMSettingPpp *) nm_setting_ppp_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ppp)); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection_fail(connection, TEST_SCRATCH_DIR, NULL); + + g_object_unref(connection); + g_clear_error(&error); +} + +static void +test_read_bridge_main(void) +{ + NMConnection * connection; + NMSettingBridge *s_bridge; + NMSettingWired * s_wired; + const char * mac; + char expected_mac_address[ETH_ALEN] = {0x00, 0x16, 0x41, 0x11, 0x22, 0x33}; + + connection = + _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bridge-main", NULL, TYPE_ETHERNET, NULL); + + g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "br0"); + + /* ===== Bridging SETTING ===== */ + + s_bridge = nm_connection_get_setting_bridge(connection); + g_assert(s_bridge); + g_assert_cmpuint(nm_setting_bridge_get_forward_delay(s_bridge), ==, 2); + g_assert(nm_setting_bridge_get_stp(s_bridge)); + g_assert_cmpuint(nm_setting_bridge_get_priority(s_bridge), ==, 32744); + g_assert_cmpuint(nm_setting_bridge_get_hello_time(s_bridge), ==, 7); + g_assert_cmpuint(nm_setting_bridge_get_max_age(s_bridge), ==, 39); + g_assert_cmpuint(nm_setting_bridge_get_ageing_time(s_bridge), ==, 235352); + g_assert_cmpuint(nm_setting_bridge_get_group_forward_mask(s_bridge), ==, 24); + g_assert(!nm_setting_bridge_get_multicast_snooping(s_bridge)); + g_assert_cmpint(nm_setting_bridge_get_vlan_filtering(s_bridge), ==, TRUE); + g_assert_cmpint(nm_setting_bridge_get_vlan_default_pvid(s_bridge), ==, 99); + + /* MAC address */ + s_wired = nm_connection_get_setting_wired(connection); + g_assert(s_wired); + mac = nm_setting_wired_get_cloned_mac_address(s_wired); + g_assert(mac); + g_assert(nm_utils_hwaddr_matches(mac, -1, expected_mac_address, ETH_ALEN)); + + g_object_unref(connection); +} + +static void +test_write_bridge_main(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingBridge * s_bridge; + NMSettingIPConfig * s_ip4, *s_ip6; + NMSettingWired * s_wired; + NMIPAddress * addr; + static const char * mac = "31:33:33:37:be:cd"; + GError * error = NULL; + gs_unref_ptrarray GPtrArray *vlans = NULL; + NMBridgeVlan * vlan; + + connection = nm_simple_connection_new(); + g_assert(connection); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Bridge Main", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_INTERFACE_NAME, + "br0", + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_BRIDGE_SETTING_NAME, + NULL); + + /* bridge setting */ + s_bridge = (NMSettingBridge *) nm_setting_bridge_new(); + nm_connection_add_setting(connection, NM_SETTING(s_bridge)); + + vlans = g_ptr_array_new_with_free_func((GDestroyNotify) nm_bridge_vlan_unref); + vlan = nm_bridge_vlan_new(10, 16); + nm_bridge_vlan_set_untagged(vlan, TRUE); + g_ptr_array_add(vlans, vlan); + vlan = nm_bridge_vlan_new(22, 22); + nm_bridge_vlan_set_pvid(vlan, TRUE); + nm_bridge_vlan_set_untagged(vlan, TRUE); + g_ptr_array_add(vlans, vlan); + vlan = nm_bridge_vlan_new(44, 0); + g_ptr_array_add(vlans, vlan); + + g_object_set(s_bridge, + NM_SETTING_BRIDGE_MAC_ADDRESS, + mac, + NM_SETTING_BRIDGE_GROUP_FORWARD_MASK, + 19008, + NM_SETTING_BRIDGE_VLAN_FILTERING, + TRUE, + NM_SETTING_BRIDGE_VLAN_DEFAULT_PVID, + 4000, + NM_SETTING_BRIDGE_VLANS, + vlans, + NULL); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP4_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_GATEWAY, + "1.1.1.1", + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NULL); + + addr = nm_ip_address_new(AF_INET, "1.1.1.3", 24, &error); + g_assert_no_error(error); + nm_setting_ip_config_add_address(s_ip4, addr); + nm_ip_address_unref(addr); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NULL); + + /* Wired setting */ + s_wired = (NMSettingWired *) nm_setting_wired_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wired)); + + nm_connection_add_setting(connection, nm_setting_proxy_new()); + + nmtst_assert_connection_verifies_without_normalization(connection); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_BRIDGE, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_read_bridge_component(void) +{ + NMConnection * connection; + NMSettingConnection *s_con; + NMSettingBridgePort *s_port; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bridge-component", + NULL, + TYPE_ETHERNET, + NULL); + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_master(s_con), ==, "br0"); + g_assert_cmpstr(nm_setting_connection_get_slave_type(s_con), + ==, + NM_SETTING_BRIDGE_SETTING_NAME); + + s_port = nm_connection_get_setting_bridge_port(connection); + g_assert(s_port); + g_assert(nm_setting_bridge_port_get_hairpin_mode(s_port)); + g_assert_cmpuint(nm_setting_bridge_port_get_priority(s_port), ==, 28); + g_assert_cmpuint(nm_setting_bridge_port_get_path_cost(s_port), ==, 100); + + g_object_unref(connection); +} + +static void +test_write_bridge_component(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSetting * s_port; + static const char * mac = "31:33:33:37:be:cd"; + guint32 mtu = 1492; + gs_unref_ptrarray GPtrArray *vlans = NULL; + NMBridgeVlan * vlan; + + connection = nm_simple_connection_new(); + g_assert(connection); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Bridge Component", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRED_SETTING_NAME, + NM_SETTING_CONNECTION_MASTER, + "br0", + NM_SETTING_CONNECTION_SLAVE_TYPE, + NM_SETTING_BRIDGE_SETTING_NAME, + NULL); + + /* Wired setting */ + s_wired = (NMSettingWired *) nm_setting_wired_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wired)); + + g_object_set(s_wired, NM_SETTING_WIRED_MAC_ADDRESS, mac, NM_SETTING_WIRED_MTU, mtu, NULL); + + /* Bridge port */ + vlans = g_ptr_array_new_with_free_func((GDestroyNotify) nm_bridge_vlan_unref); + vlan = nm_bridge_vlan_new(1, 0); + nm_bridge_vlan_set_untagged(vlan, TRUE); + g_ptr_array_add(vlans, vlan); + vlan = nm_bridge_vlan_new(4, 4094); + nm_bridge_vlan_set_untagged(vlan, TRUE); + g_ptr_array_add(vlans, vlan); + vlan = nm_bridge_vlan_new(2, 2); + nm_bridge_vlan_set_pvid(vlan, TRUE); + g_ptr_array_add(vlans, vlan); + + s_port = nm_setting_bridge_port_new(); + nm_connection_add_setting(connection, s_port); + g_object_set(s_port, + NM_SETTING_BRIDGE_PORT_PRIORITY, + 50, + NM_SETTING_BRIDGE_PORT_PATH_COST, + 33, + NM_SETTING_BRIDGE_PORT_VLANS, + vlans, + NULL); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connec_exp(connection, + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR "/ifcfg-Test_Write_Bridge_Component.cexpected", + &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_read_bridge_missing_stp(void) +{ + NMConnection * connection; + NMSettingBridge *s_bridge; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bridge-missing-stp", + NULL, + TYPE_BRIDGE, + NULL); + + g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "br0"); + + /* ===== Bridging SETTING ===== */ + + s_bridge = nm_connection_get_setting_bridge(connection); + g_assert(s_bridge); + g_assert(nm_setting_bridge_get_stp(s_bridge) == FALSE); + + g_object_unref(connection); +} + +#define TEST_IFCFG_VLAN_INTERFACE TEST_IFCFG_DIR "/ifcfg-test-vlan-interface" + +static void +test_read_vlan_interface(void) +{ + NMConnection * connection; + NMSettingVlan *s_vlan; + guint32 from = 0, to = 0; + + connection = _connection_from_file(TEST_IFCFG_VLAN_INTERFACE, NULL, TYPE_ETHERNET, NULL); + + g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "vlan43"); + + s_vlan = nm_connection_get_setting_vlan(connection); + g_assert(s_vlan); + + g_assert_cmpstr(nm_setting_vlan_get_parent(s_vlan), ==, "eth9"); + g_assert_cmpint(nm_setting_vlan_get_id(s_vlan), ==, 43); + g_assert_cmpint(nm_setting_vlan_get_flags(s_vlan), + ==, + NM_VLAN_FLAG_GVRP | NM_VLAN_FLAG_LOOSE_BINDING | NM_VLAN_FLAG_REORDER_HEADERS); + + /* Ingress map */ + g_assert_cmpint(nm_setting_vlan_get_num_priorities(s_vlan, NM_VLAN_INGRESS_MAP), ==, 2); + + g_assert(nm_setting_vlan_get_priority(s_vlan, NM_VLAN_INGRESS_MAP, 0, &from, &to)); + g_assert_cmpint(from, ==, 0); + g_assert_cmpint(to, ==, 1); + + g_assert(nm_setting_vlan_get_priority(s_vlan, NM_VLAN_INGRESS_MAP, 1, &from, &to)); + g_assert_cmpint(from, ==, 2); + g_assert_cmpint(to, ==, 5); + + /* Egress map */ + g_assert_cmpint(nm_setting_vlan_get_num_priorities(s_vlan, NM_VLAN_EGRESS_MAP), ==, 3); + + g_assert(nm_setting_vlan_get_priority(s_vlan, NM_VLAN_EGRESS_MAP, 0, &from, &to)); + g_assert_cmpint(from, ==, 3); + g_assert_cmpint(to, ==, 1); + + g_assert(nm_setting_vlan_get_priority(s_vlan, NM_VLAN_EGRESS_MAP, 1, &from, &to)); + g_assert_cmpint(from, ==, 12); + g_assert_cmpint(to, ==, 3); + + g_assert(nm_setting_vlan_get_priority(s_vlan, NM_VLAN_EGRESS_MAP, 2, &from, &to)); + g_assert_cmpint(from, ==, 14); + g_assert_cmpint(to, ==, 7); + + g_object_unref(connection); +} + +#define TEST_IFCFG_VLAN_ONLY_VLANID TEST_IFCFG_DIR "/ifcfg-test-vlan-only-vlanid" + +static void +test_read_vlan_only_vlan_id(void) +{ + NMConnection * connection; + NMSettingVlan *s_vlan; + + connection = _connection_from_file(TEST_IFCFG_VLAN_ONLY_VLANID, NULL, TYPE_ETHERNET, NULL); + + g_assert(nm_connection_get_interface_name(connection) == NULL); + + s_vlan = nm_connection_get_setting_vlan(connection); + g_assert(s_vlan); + + g_assert_cmpstr(nm_setting_vlan_get_parent(s_vlan), ==, "eth9"); + g_assert_cmpint(nm_setting_vlan_get_id(s_vlan), ==, 43); + g_assert_cmpint(nm_setting_vlan_get_flags(s_vlan), ==, NM_VLAN_FLAG_REORDER_HEADERS); + + g_object_unref(connection); +} + +static void +test_read_vlan_only_device(void) +{ + NMConnection * connection; + NMSettingVlan *s_vlan; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-vlan-only-device", + NULL, + TYPE_ETHERNET, + NULL); + + g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "eth0.9"); + + s_vlan = nm_connection_get_setting_vlan(connection); + g_assert(s_vlan); + + g_assert_cmpstr(nm_setting_vlan_get_parent(s_vlan), ==, "eth0"); + g_assert_cmpint(nm_setting_vlan_get_id(s_vlan), ==, 9); + + g_object_unref(connection); +} + +static void +test_read_vlan_physdev(void) +{ + NMConnection * connection; + NMSettingVlan *s_vlan; + + connection = + _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-vlan-physdev", NULL, TYPE_ETHERNET, NULL); + + g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "vlan0.3"); + + s_vlan = nm_connection_get_setting_vlan(connection); + g_assert(s_vlan); + + g_assert_cmpstr(nm_setting_vlan_get_parent(s_vlan), ==, "eth0"); + g_assert_cmpint(nm_setting_vlan_get_id(s_vlan), ==, 3); + + g_object_unref(connection); +} + +static void +test_read_vlan_reorder_hdr_1(void) +{ + NMConnection * connection; + NMSettingVlan *s_vlan; + + NMTST_EXPECT_NM_WARN("*REORDER_HDR key is deprecated, use VLAN_FLAGS*"); + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-vlan-reorder-hdr-1", + NULL, + TYPE_ETHERNET, + NULL); + g_test_assert_expected_messages(); + + g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "vlan0.3"); + + s_vlan = nm_connection_get_setting_vlan(connection); + g_assert(s_vlan); + + g_assert_cmpstr(nm_setting_vlan_get_parent(s_vlan), ==, "eth0"); + g_assert_cmpint(nm_setting_vlan_get_id(s_vlan), ==, 3); + /* Check that REORDER_HDR=0 is ignored */ + g_assert_cmpint(nm_setting_vlan_get_flags(s_vlan), ==, NM_VLAN_FLAG_REORDER_HEADERS); + + g_object_unref(connection); +} + +static void +test_read_vlan_reorder_hdr_2(void) +{ + NMConnection * connection; + NMSettingVlan *s_vlan; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-vlan-reorder-hdr-2", + NULL, + TYPE_ETHERNET, + NULL); + + g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "vlan0.3"); + + s_vlan = nm_connection_get_setting_vlan(connection); + g_assert(s_vlan); + + g_assert_cmpstr(nm_setting_vlan_get_parent(s_vlan), ==, "eth0"); + g_assert_cmpint(nm_setting_vlan_get_id(s_vlan), ==, 3); + /* Check that VLAN_FLAGS=NO_REORDER_HDR works */ + g_assert_cmpint(nm_setting_vlan_get_flags(s_vlan), ==, NM_VLAN_FLAG_LOOSE_BINDING); + + g_object_unref(connection); +} + +static void +test_read_vlan_flags_1(void) +{ + NMConnection * connection; + NMSettingVlan *s_vlan; + + connection = + _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-vlan-flags-1", NULL, TYPE_ETHERNET, NULL); + + g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "super-vlan"); + + s_vlan = nm_connection_get_setting_vlan(connection); + g_assert(s_vlan); + + g_assert_cmpstr(nm_setting_vlan_get_parent(s_vlan), ==, "eth9"); + g_assert_cmpint(nm_setting_vlan_get_id(s_vlan), ==, 44); + g_assert_cmpint(nm_setting_vlan_get_flags(s_vlan), + ==, + NM_VLAN_FLAG_LOOSE_BINDING | NM_VLAN_FLAG_REORDER_HEADERS); + + g_object_unref(connection); +} + +static void +test_read_vlan_flags_2(void) +{ + NMConnection * connection; + NMSettingVlan *s_vlan; + + connection = + _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-vlan-flags-2", NULL, TYPE_ETHERNET, NULL); + + g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "super-vlan"); + + s_vlan = nm_connection_get_setting_vlan(connection); + g_assert(s_vlan); + + g_assert_cmpstr(nm_setting_vlan_get_parent(s_vlan), ==, "eth9"); + g_assert_cmpint(nm_setting_vlan_get_id(s_vlan), ==, 44); + g_assert_cmpint(nm_setting_vlan_get_flags(s_vlan), + ==, + NM_VLAN_FLAG_GVRP | NM_VLAN_FLAG_LOOSE_BINDING | NM_VLAN_FLAG_REORDER_HEADERS); + + g_object_unref(connection); +} + +static void +test_write_vlan(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + + connection = _connection_from_file(TEST_IFCFG_VLAN_INTERFACE, NULL, TYPE_VLAN, NULL); + + _writer_new_connec_exp(connection, + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR "/ifcfg-Vlan_test-vlan-interface.cexpected", + &testfile); +} + +static void +test_write_vlan_flags(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + + connection = + _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-vlan-flags-2", NULL, TYPE_VLAN, NULL); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_write_vlan_only_vlanid(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + + connection = _connection_from_file(TEST_IFCFG_VLAN_ONLY_VLANID, NULL, TYPE_VLAN, NULL); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_write_vlan_reorder_hdr(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingVlan * s_vlan; + NMSettingWired * s_wired; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write VLAN reorder_hdr", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + FALSE, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_VLAN_SETTING_NAME, + NULL); + + /* Wired setting */ + s_wired = (NMSettingWired *) nm_setting_wired_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wired)); + + /* VLAN setting */ + s_vlan = (NMSettingVlan *) nm_setting_vlan_new(); + nm_connection_add_setting(connection, NM_SETTING(s_vlan)); + + g_object_set(s_vlan, + NM_SETTING_VLAN_PARENT, + "eth0", + NM_SETTING_VLAN_ID, + 444, + NM_SETTING_VLAN_FLAGS, + 1, + NULL); + + _writer_new_connec_exp(connection, + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR "/ifcfg-Test_Write_VLAN_reorder_hdr.cexpected", + &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_write_ethernet_missing_ipv6(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + + connection = nm_simple_connection_new(); + g_assert(connection); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Ethernet Without IPv6 Setting", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRED_SETTING_NAME, + NULL); + + /* Wired setting */ + s_wired = (NMSettingWired *) nm_setting_wired_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wired)); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + g_object_set(s_ip4, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP4_CONFIG_METHOD_AUTO, + NM_SETTING_IP4_CONFIG_DHCP_CLIENT_ID, + "random-client-id-00:22:33", + NM_SETTING_IP_CONFIG_IGNORE_AUTO_ROUTES, + TRUE, + NM_SETTING_IP_CONFIG_IGNORE_AUTO_DNS, + TRUE, + NULL); + + /* IP6 setting */ + /* + * We intentionally don't add IPv6 setting here. ifcfg-rh plugin should regard + * missing IPv6 as IPv6 with NM_SETTING_IP6_CONFIG_METHOD_AUTO method. + */ + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_read_ibft_ignored(void) +{ + gs_free_error GError *error = NULL; + + _connection_from_file_fail(TEST_IFCFG_DIR "/ifcfg-test-ibft", NULL, TYPE_ETHERNET, &error); + g_assert_error(error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION); +} + +static void +test_read_bond_main(void) +{ + NMConnection * connection; + NMSettingBond *s_bond; + + connection = + _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bond-main", NULL, TYPE_ETHERNET, NULL); + + g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "bond0"); + + /* ===== Bonding SETTING ===== */ + + s_bond = nm_connection_get_setting_bond(connection); + g_assert(s_bond); + + g_assert_cmpstr(nm_setting_bond_get_option_by_name(s_bond, NM_SETTING_BOND_OPTION_MIIMON), + ==, + "100"); + + g_object_unref(connection); +} + +static void +test_read_bond_eth_type(void) +{ + NMConnection * connection; + NMSettingBond *s_bond; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bond-eth-type", + NULL, + TYPE_ETHERNET, + NULL); + + g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "bond0"); + + /* ===== Bonding SETTING ===== */ + + s_bond = nm_connection_get_setting_bond(connection); + g_assert(s_bond); + + g_assert_cmpstr(nm_setting_bond_get_option_by_name(s_bond, NM_SETTING_BOND_OPTION_MIIMON), + ==, + "213"); + g_assert_cmpstr(nm_setting_bond_get_option_by_name(s_bond, NM_SETTING_BOND_OPTION_LACP_RATE), + ==, + "1"); + + g_object_unref(connection); +} + +static void +test_write_bond_main(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingBond * s_bond; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + NMSettingWired * s_wired; + NMIPAddress * addr; + GError * error = NULL; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Bond Main", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_INTERFACE_NAME, + "bond0", + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_BOND_SETTING_NAME, + NULL); + + /* Wired setting */ + s_wired = (NMSettingWired *) nm_setting_wired_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wired)); + + /* bond setting */ + s_bond = (NMSettingBond *) nm_setting_bond_new(); + nm_connection_add_setting(connection, NM_SETTING(s_bond)); + + nm_setting_bond_add_option(s_bond, NM_SETTING_BOND_OPTION_DOWNDELAY, "5"); + nm_setting_bond_add_option(s_bond, NM_SETTING_BOND_OPTION_UPDELAY, "10"); + nm_setting_bond_add_option(s_bond, NM_SETTING_BOND_OPTION_MIIMON, "100"); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP4_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_GATEWAY, + "1.1.1.1", + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NULL); + + addr = nm_ip_address_new(AF_INET, "1.1.1.3", 24, &error); + g_assert_no_error(error); + nm_setting_ip_config_add_address(s_ip4, addr); + nm_ip_address_unref(addr); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NULL); + + nm_connection_add_setting(connection, nm_setting_proxy_new()); + + nmtst_assert_connection_verifies_without_normalization(connection); + + _writer_new_connec_exp(connection, + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR "/ifcfg-Test_Write_Bond_Main.cexpected", + &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_BOND, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_read_bond_slave(void) +{ + NMConnection * connection; + NMSettingConnection *s_con; + + connection = + _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bond-slave", NULL, TYPE_ETHERNET, NULL); + g_test_assert_expected_messages(); + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + + g_assert_cmpstr(nm_setting_connection_get_master(s_con), ==, "bond0"); + + g_assert_cmpstr(nm_setting_connection_get_slave_type(s_con), ==, NM_SETTING_BOND_SETTING_NAME); + + g_object_unref(connection); +} + +static void +test_write_bond_slave(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + static const char * mac = "31:33:33:37:be:cd"; + guint32 mtu = 1492; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Bond Slave", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRED_SETTING_NAME, + NM_SETTING_CONNECTION_MASTER, + "bond0", + NM_SETTING_CONNECTION_SLAVE_TYPE, + NM_SETTING_BOND_SETTING_NAME, + NULL); + + /* Wired setting */ + s_wired = (NMSettingWired *) nm_setting_wired_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wired)); + + g_object_set(s_wired, NM_SETTING_WIRED_MAC_ADDRESS, mac, NM_SETTING_WIRED_MTU, mtu, NULL); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_read_infiniband(void) +{ + NMConnection * connection; + NMSettingInfiniband *s_infiniband; + char * unmanaged = NULL; + const char * mac; + char expected_mac_address[INFINIBAND_ALEN] = {0x80, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, + 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, + 0xdd, 0xee, 0xff, 0x00, 0x11, 0x22}; + const char *transport_mode; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-infiniband", + NULL, + TYPE_INFINIBAND, + &unmanaged); + g_assert(!unmanaged); + + /* ===== INFINIBAND SETTING ===== */ + + s_infiniband = nm_connection_get_setting_infiniband(connection); + g_assert(s_infiniband); + + /* MAC address */ + mac = nm_setting_infiniband_get_mac_address(s_infiniband); + g_assert(mac); + g_assert(nm_utils_hwaddr_matches(mac, -1, expected_mac_address, sizeof(expected_mac_address))); + + /* Transport mode */ + transport_mode = nm_setting_infiniband_get_transport_mode(s_infiniband); + g_assert(transport_mode); + g_assert_cmpstr(transport_mode, ==, "connected"); + + g_object_unref(connection); +} + +static void +test_write_infiniband(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingInfiniband * s_infiniband; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + const char * mac = "80:00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22"; + guint32 mtu = 65520; + NMIPAddress *addr; + GError * error = NULL; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write InfiniBand", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_INFINIBAND_SETTING_NAME, + NULL); + + /* InfiniBand setting */ + s_infiniband = (NMSettingInfiniband *) nm_setting_infiniband_new(); + nm_connection_add_setting(connection, NM_SETTING(s_infiniband)); + + g_object_set(s_infiniband, + NM_SETTING_INFINIBAND_MAC_ADDRESS, + mac, + NM_SETTING_INFINIBAND_MTU, + mtu, + NM_SETTING_INFINIBAND_TRANSPORT_MODE, + "connected", + NULL); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP4_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_GATEWAY, + "1.1.1.1", + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NULL); + + addr = nm_ip_address_new(AF_INET, "1.1.1.3", 24, &error); + g_assert_no_error(error); + nm_setting_ip_config_add_address(s_ip4, addr); + nm_ip_address_unref(addr); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NULL); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_INFINIBAND, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_read_bond_slave_ib(void) +{ + gs_unref_object NMConnection *connection = NULL; + NMSettingConnection * s_con; + + connection = + _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bond-slave-ib", NULL, NULL, NULL); + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + + g_assert_cmpstr(nm_setting_connection_get_master(s_con), ==, "bond0"); + g_assert_cmpstr(nm_setting_connection_get_slave_type(s_con), ==, NM_SETTING_BOND_SETTING_NAME); +} + +static void +test_write_bond_slave_ib(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingInfiniband * s_infiniband; + static const char *mac = "80:00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff:00:11:22"; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Bond Slave InfiniBand", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_INFINIBAND_SETTING_NAME, + NM_SETTING_CONNECTION_MASTER, + "bond0", + NM_SETTING_CONNECTION_SLAVE_TYPE, + NM_SETTING_BOND_SETTING_NAME, + NULL); + + /* InfiniBand setting */ + s_infiniband = (NMSettingInfiniband *) nm_setting_infiniband_new(); + nm_connection_add_setting(connection, NM_SETTING(s_infiniband)); + + g_object_set(s_infiniband, + NM_SETTING_INFINIBAND_MAC_ADDRESS, + mac, + NM_SETTING_INFINIBAND_MTU, + 2044, + NM_SETTING_INFINIBAND_TRANSPORT_MODE, + "datagram", + NULL); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + + reread = _connection_from_file(testfile, NULL, NULL, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_read_bond_opts_mode_numeric(void) +{ + NMConnection * connection; + NMSettingConnection *s_con; + NMSettingBond * s_bond; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-bond-mode-numeric", + NULL, + TYPE_ETHERNET, + NULL); + + g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "bond0"); + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con), + ==, + NM_SETTING_BOND_SETTING_NAME); + + s_bond = nm_connection_get_setting_bond(connection); + g_assert(s_bond); + g_assert_cmpstr(nm_setting_bond_get_option_by_name(s_bond, NM_SETTING_BOND_OPTION_MODE), + ==, + "802.3ad"); + + g_object_unref(connection); +} + +#define DCB_ALL_FLAGS \ + (NM_SETTING_DCB_FLAG_ENABLE | NM_SETTING_DCB_FLAG_ADVERTISE | NM_SETTING_DCB_FLAG_WILLING) + +static void +test_read_dcb_basic(void) +{ + NMConnection *connection; + NMSettingDcb *s_dcb; + guint i; + guint expected_group_ids[8] = {0, 0, 0, 0, 1, 1, 1, 0xF}; + guint expected_group_bandwidths[8] = {25, 0, 0, 75, 0, 0, 0, 0}; + guint expected_bandwidths[8] = {5, 10, 30, 25, 10, 50, 5, 0}; + gboolean expected_strict[8] = {FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, FALSE, TRUE}; + guint expected_traffic_classes[8] = {7, 6, 5, 4, 3, 2, 1, 0}; + gboolean expected_pfcs[8] = {TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, TRUE, FALSE}; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-dcb", NULL, TYPE_ETHERNET, NULL); + + s_dcb = nm_connection_get_setting_dcb(connection); + g_assert(s_dcb); + + g_assert_cmpint(nm_setting_dcb_get_app_fcoe_flags(s_dcb), ==, DCB_ALL_FLAGS); + g_assert_cmpint(nm_setting_dcb_get_app_fcoe_priority(s_dcb), ==, 7); + + g_assert_cmpint(nm_setting_dcb_get_app_iscsi_flags(s_dcb), ==, DCB_ALL_FLAGS); + g_assert_cmpint(nm_setting_dcb_get_app_iscsi_priority(s_dcb), ==, 6); + + g_assert_cmpint(nm_setting_dcb_get_app_fip_flags(s_dcb), ==, DCB_ALL_FLAGS); + g_assert_cmpint(nm_setting_dcb_get_app_fip_priority(s_dcb), ==, 2); + + g_assert_cmpint(nm_setting_dcb_get_priority_flow_control_flags(s_dcb), + ==, + (NM_SETTING_DCB_FLAG_ENABLE | NM_SETTING_DCB_FLAG_ADVERTISE)); + for (i = 0; i < 8; i++) + g_assert_cmpint(nm_setting_dcb_get_priority_flow_control(s_dcb, i), ==, expected_pfcs[i]); + + g_assert_cmpint(nm_setting_dcb_get_priority_group_flags(s_dcb), ==, DCB_ALL_FLAGS); + + /* Group IDs */ + for (i = 0; i < 8; i++) + g_assert_cmpint(nm_setting_dcb_get_priority_group_id(s_dcb, i), ==, expected_group_ids[i]); + + /* Group bandwidth */ + for (i = 0; i < 8; i++) + g_assert_cmpint(nm_setting_dcb_get_priority_group_bandwidth(s_dcb, i), + ==, + expected_group_bandwidths[i]); + + /* User priority bandwidth */ + for (i = 0; i < 8; i++) + g_assert_cmpint(nm_setting_dcb_get_priority_bandwidth(s_dcb, i), + ==, + expected_bandwidths[i]); + + /* Strict bandwidth */ + for (i = 0; i < 8; i++) + g_assert_cmpint(nm_setting_dcb_get_priority_strict_bandwidth(s_dcb, i), + ==, + expected_strict[i]); + + /* Traffic class */ + for (i = 0; i < 8; i++) + g_assert_cmpint(nm_setting_dcb_get_priority_traffic_class(s_dcb, i), + ==, + expected_traffic_classes[i]); + + g_object_unref(connection); +} + +static void +test_write_dcb_basic(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSettingDcb * s_dcb; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + guint i; + const guint group_ids[8] = {4, 0xF, 6, 0xF, 1, 7, 3, 0xF}; + const guint group_bandwidths[8] = {10, 20, 15, 10, 2, 3, 35, 5}; + const guint bandwidths[8] = {10, 20, 30, 40, 50, 10, 0, 25}; + const gboolean strict[8] = {TRUE, FALSE, TRUE, TRUE, FALSE, FALSE, FALSE, TRUE}; + const guint traffic_classes[8] = {3, 4, 7, 2, 1, 0, 5, 6}; + const gboolean pfcs[8] = {TRUE, TRUE, FALSE, TRUE, FALSE, TRUE, TRUE, FALSE}; + + connection = nm_simple_connection_new(); + + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + g_object_set(G_OBJECT(s_con), + NM_SETTING_CONNECTION_ID, + "dcb-test", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRED_SETTING_NAME, + NM_SETTING_CONNECTION_INTERFACE_NAME, + "eth0", + NULL); + + /* Wired setting */ + s_wired = (NMSettingWired *) nm_setting_wired_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wired)); + + /* IP stuff */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + g_object_set(G_OBJECT(s_ip4), + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP4_CONFIG_METHOD_AUTO, + NULL); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + g_object_set(G_OBJECT(s_ip6), + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP6_CONFIG_METHOD_AUTO, + NULL); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + /* DCB */ + s_dcb = (NMSettingDcb *) nm_setting_dcb_new(); + nm_connection_add_setting(connection, NM_SETTING(s_dcb)); + + g_object_set(G_OBJECT(s_dcb), + NM_SETTING_DCB_APP_FCOE_FLAGS, + DCB_ALL_FLAGS, + NM_SETTING_DCB_APP_FCOE_PRIORITY, + 5, + NM_SETTING_DCB_APP_ISCSI_FLAGS, + DCB_ALL_FLAGS, + NM_SETTING_DCB_APP_ISCSI_PRIORITY, + 1, + NM_SETTING_DCB_APP_FIP_FLAGS, + DCB_ALL_FLAGS, + NM_SETTING_DCB_APP_FIP_PRIORITY, + 3, + NM_SETTING_DCB_PRIORITY_FLOW_CONTROL_FLAGS, + DCB_ALL_FLAGS, + NM_SETTING_DCB_PRIORITY_GROUP_FLAGS, + DCB_ALL_FLAGS, + NULL); + + for (i = 0; i < 8; i++) { + nm_setting_dcb_set_priority_flow_control(s_dcb, i, pfcs[i]); + nm_setting_dcb_set_priority_group_id(s_dcb, i, group_ids[i]); + nm_setting_dcb_set_priority_group_bandwidth(s_dcb, i, group_bandwidths[i]); + nm_setting_dcb_set_priority_bandwidth(s_dcb, i, bandwidths[i]); + nm_setting_dcb_set_priority_strict_bandwidth(s_dcb, i, strict[i]); + nm_setting_dcb_set_priority_traffic_class(s_dcb, i, traffic_classes[i]); + } + + nmtst_assert_connection_verifies(connection); + + _writer_new_connec_exp(connection, + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR "//ifcfg-dcb-test.cexpected", + &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_read_dcb_default_app_priorities(void) +{ + gs_unref_object NMConnection *connection = NULL; + NMSettingDcb * s_dcb; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-dcb-default-app-priorities", + NULL, + TYPE_ETHERNET, + NULL); + + s_dcb = nm_connection_get_setting_dcb(connection); + g_assert(s_dcb); + + g_assert_cmpint(nm_setting_dcb_get_app_fcoe_flags(s_dcb), ==, NM_SETTING_DCB_FLAG_ENABLE); + g_assert_cmpint(nm_setting_dcb_get_app_fcoe_priority(s_dcb), ==, -1); + + g_assert_cmpint(nm_setting_dcb_get_app_iscsi_flags(s_dcb), ==, NM_SETTING_DCB_FLAG_ENABLE); + g_assert_cmpint(nm_setting_dcb_get_app_iscsi_priority(s_dcb), ==, -1); + + g_assert_cmpint(nm_setting_dcb_get_app_fip_flags(s_dcb), ==, NM_SETTING_DCB_FLAG_ENABLE); + g_assert_cmpint(nm_setting_dcb_get_app_fip_priority(s_dcb), ==, -1); +} + +static void +test_read_dcb_bad_booleans(void) +{ + gs_free_error GError *error = NULL; + + NMTST_EXPECT_NM_WARN("*invalid DCB_PG_STRICT value*not all 0s and 1s*"); + _connection_from_file_fail(TEST_IFCFG_DIR "/ifcfg-test-dcb-bad-booleans", + NULL, + TYPE_ETHERNET, + &error); + g_test_assert_expected_messages(); + + g_assert_error(error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION); + g_assert(strstr(error->message, "invalid boolean digit")); +} + +static void +test_read_dcb_short_booleans(void) +{ + gs_free_error GError *error = NULL; + + NMTST_EXPECT_NM_WARN("*DCB_PG_STRICT value*8 characters*"); + _connection_from_file_fail(TEST_IFCFG_DIR "/ifcfg-test-dcb-short-booleans", + NULL, + TYPE_ETHERNET, + &error); + g_test_assert_expected_messages(); + + g_assert_error(error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION); + g_assert(strstr(error->message, "boolean array must be 8 characters")); +} + +static void +test_read_dcb_bad_uints(void) +{ + gs_free_error GError *error = NULL; + + NMTST_EXPECT_NM_WARN("*invalid DCB_PG_UP2TC value*not 0 - 7*"); + _connection_from_file_fail(TEST_IFCFG_DIR "/ifcfg-test-dcb-bad-uints", + NULL, + TYPE_ETHERNET, + &error); + g_test_assert_expected_messages(); + + g_assert_error(error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION); + g_assert(strstr(error->message, "invalid uint digit")); +} + +static void +test_read_dcb_short_uints(void) +{ + gs_free_error GError *error = NULL; + + NMTST_EXPECT_NM_WARN("*DCB_PG_UP2TC value*8 characters*"); + _connection_from_file_fail(TEST_IFCFG_DIR "/ifcfg-test-dcb-short-uints", + NULL, + TYPE_ETHERNET, + &error); + g_test_assert_expected_messages(); + + g_assert_error(error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION); + g_assert(strstr(error->message, "uint array must be 8 characters")); +} + +static void +test_read_dcb_bad_percent(void) +{ + gs_free_error GError *error = NULL; + + NMTST_EXPECT_NM_WARN("*invalid DCB_PG_PCT percentage value*"); + _connection_from_file_fail(TEST_IFCFG_DIR "/ifcfg-test-dcb-bad-percent", + NULL, + TYPE_ETHERNET, + &error); + g_test_assert_expected_messages(); + + g_assert_error(error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION); + g_assert(strstr(error->message, "invalid percent element")); +} + +static void +test_read_dcb_short_percent(void) +{ + gs_free_error GError *error = NULL; + + NMTST_EXPECT_NM_WARN("*invalid DCB_PG_PCT percentage list value*"); + _connection_from_file_fail(TEST_IFCFG_DIR "/ifcfg-test-dcb-short-percent", + NULL, + TYPE_ETHERNET, + &error); + g_test_assert_expected_messages(); + + g_assert_error(error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION); + g_assert(strstr(error->message, "percent array must be 8 elements")); +} + +static void +test_read_dcb_pgpct_not_100(void) +{ + gs_free_error GError *error = NULL; + + NMTST_EXPECT_NM_WARN("*DCB_PG_PCT percentages do not equal 100*"); + _connection_from_file_fail(TEST_IFCFG_DIR "/ifcfg-test-dcb-pgpct-not-100", + NULL, + TYPE_ETHERNET, + &error); + g_test_assert_expected_messages(); + + g_assert_error(error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION); + g_assert(strstr(error->message, "invalid percentage sum")); +} + +static void +test_read_fcoe_mode(gconstpointer user_data) +{ + gs_unref_object NMConnection *connection = NULL; + gs_free char * file = NULL; + const char * expected_mode = user_data; + NMSettingDcb * s_dcb; + + file = g_strdup_printf(TEST_IFCFG_DIR "/ifcfg-test-fcoe-%s", expected_mode); + connection = _connection_from_file(file, NULL, TYPE_ETHERNET, NULL); + + s_dcb = nm_connection_get_setting_dcb(connection); + g_assert(s_dcb); + + g_assert_cmpint(nm_setting_dcb_get_app_fcoe_flags(s_dcb), ==, NM_SETTING_DCB_FLAG_ENABLE); + g_assert_cmpstr(nm_setting_dcb_get_app_fcoe_mode(s_dcb), ==, expected_mode); +} + +static void +test_write_fcoe_mode(gconstpointer user_data) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + const char * expected_mode = user_data; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSettingDcb * s_dcb; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + shvarFile * ifcfg; + + connection = nm_simple_connection_new(); + + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + g_object_set(G_OBJECT(s_con), + NM_SETTING_CONNECTION_ID, + "fcoe-test", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRED_SETTING_NAME, + NM_SETTING_CONNECTION_INTERFACE_NAME, + "eth0", + NULL); + + /* Wired setting */ + s_wired = (NMSettingWired *) nm_setting_wired_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wired)); + + /* IP stuff */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + g_object_set(G_OBJECT(s_ip4), + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP4_CONFIG_METHOD_AUTO, + NULL); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + g_object_set(G_OBJECT(s_ip6), + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP6_CONFIG_METHOD_AUTO, + NULL); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + /* DCB */ + s_dcb = (NMSettingDcb *) nm_setting_dcb_new(); + nm_connection_add_setting(connection, NM_SETTING(s_dcb)); + + g_object_set(G_OBJECT(s_dcb), + NM_SETTING_DCB_APP_FCOE_FLAGS, + NM_SETTING_DCB_FLAG_ENABLE, + NM_SETTING_DCB_APP_FCOE_MODE, + expected_mode, + NULL); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + + ifcfg = _svOpenFile(testfile); + _svGetValue_check(ifcfg, "DCB_APP_FCOE_MODE", expected_mode); + svCloseFile(ifcfg); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_read_team_master(gconstpointer user_data) +{ + const char *const PATH_NAME = user_data; + NMConnection * connection; + NMSettingConnection *s_con; + NMSettingTeam * s_team; + const char * expected_config = + "{\"device\": \"team0\", \"link_watch\": {\"name\": \"ethtool\"}}"; + + connection = _connection_from_file(PATH_NAME, NULL, TYPE_ETHERNET, NULL); + + g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "team0"); + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con), + ==, + NM_SETTING_TEAM_SETTING_NAME); + + s_team = nm_connection_get_setting_team(connection); + g_assert(s_team); + g_assert_cmpstr(nm_setting_team_get_config(s_team), ==, expected_config); + + g_object_unref(connection); +} + +static void +test_read_team_master_invalid(gconstpointer user_data) +{ + const char *const PATH_NAME = user_data; + gs_free_error GError *error = NULL; + gs_unref_object NMConnection *connection = NULL; + + if (nm_json_vt()) { + _connection_from_file_fail(PATH_NAME, NULL, TYPE_ETHERNET, &error); + + g_assert_error(error, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_INVALID_PROPERTY); + g_assert(strstr(error->message, _("invalid json"))); + } else + connection = _connection_from_file(PATH_NAME, NULL, TYPE_ETHERNET, NULL); +} + +static void +test_write_team_master(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingTeam * s_team; + NMSettingWired * s_wired; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + const char * expected_config = + "{\"device\": \"team0\", \"link_watch\": {\"name\": \"ethtool\"}}"; + shvarFile *f; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Team Master", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_INTERFACE_NAME, + "team0", + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_TEAM_SETTING_NAME, + NULL); + + /* Team setting */ + s_team = (NMSettingTeam *) nm_setting_team_new(); + nm_connection_add_setting(connection, NM_SETTING(s_team)); + + g_object_set(s_team, NM_SETTING_TEAM_CONFIG, expected_config, NULL); + + /* Wired setting */ + s_wired = (NMSettingWired *) nm_setting_wired_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wired)); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL); + + nm_connection_add_setting(connection, nm_setting_proxy_new()); + + nmtst_assert_connection_verifies_without_normalization(connection); + + _writer_new_connection(connection, TEST_SCRATCH_DIR, &testfile); + + f = _svOpenFile(testfile); + _svGetValue_check(f, "DEVICETYPE", "Team"); + _svGetValue_check(f, "TEAM_CONFIG", expected_config); + svCloseFile(f); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_read_team_port(gconstpointer user_data) +{ + const char *const PATH_NAME = user_data; + NMConnection * connection; + NMSettingConnection *s_con; + NMSettingTeamPort * s_team_port; + const char * expected_config = "{\"p4p1\": {\"prio\": -10, \"sticky\": true}}"; + + connection = _connection_from_file(PATH_NAME, NULL, TYPE_ETHERNET, NULL); + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con), + ==, + NM_SETTING_WIRED_SETTING_NAME); + g_assert_cmpstr(nm_setting_connection_get_master(s_con), ==, "team0"); + + s_team_port = nm_connection_get_setting_team_port(connection); + g_assert(s_team_port); + g_assert_cmpstr(nm_setting_team_port_get_config(s_team_port), ==, expected_config); + + g_object_unref(connection); +} + +static void +test_write_team_port(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingTeamPort * s_team_port; + NMSettingWired * s_wired; + const char * expected_config = "{\"p4p1\": {\"prio\": -10, \"sticky\": true}}"; + shvarFile * f; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Team Port", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRED_SETTING_NAME, + NM_SETTING_CONNECTION_MASTER, + "team0", + NM_SETTING_CONNECTION_SLAVE_TYPE, + NM_SETTING_TEAM_SETTING_NAME, + NULL); + + /* Team setting */ + s_team_port = (NMSettingTeamPort *) nm_setting_team_port_new(); + nm_connection_add_setting(connection, NM_SETTING(s_team_port)); + g_object_set(s_team_port, NM_SETTING_TEAM_PORT_CONFIG, expected_config, NULL); + + /* Wired setting */ + s_wired = (NMSettingWired *) nm_setting_wired_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wired)); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connec_exp(connection, + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR "/ifcfg-Test_Write_Team_Port.cexpected", + &testfile); + + f = _svOpenFile(testfile); + _svGetValue_check(f, "TYPE", NULL); + _svGetValue_check(f, "DEVICETYPE", "TeamPort"); + _svGetValue_check(f, "TEAM_PORT_CONFIG", expected_config); + _svGetValue_check(f, "TEAM_MASTER", "team0"); + svCloseFile(f); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_write_team_infiniband_port(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingTeamPort * s_team_port; + NMSettingInfiniband * s_inf; + const char * expected_config = "{\"inf1\": {\"prio\": -10, \"sticky\": true}}"; + shvarFile * f; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Team Infiniband Port", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_INFINIBAND_SETTING_NAME, + NM_SETTING_CONNECTION_MASTER, + "team0", + NM_SETTING_CONNECTION_SLAVE_TYPE, + NM_SETTING_TEAM_SETTING_NAME, + NM_SETTING_CONNECTION_INTERFACE_NAME, + "inf1", + NULL); + + /* Team setting */ + s_team_port = (NMSettingTeamPort *) nm_setting_team_port_new(); + nm_connection_add_setting(connection, NM_SETTING(s_team_port)); + g_object_set(s_team_port, NM_SETTING_TEAM_PORT_CONFIG, expected_config, NULL); + + /* Infiniband setting */ + s_inf = (NMSettingInfiniband *) nm_setting_infiniband_new(); + nm_connection_add_setting(connection, NM_SETTING(s_inf)); + g_object_set(s_inf, NM_SETTING_INFINIBAND_TRANSPORT_MODE, "datagram", NULL); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connec_exp(connection, + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR "/ifcfg-Test_Write_Team_Infiniband_Port.cexpected", + &testfile); + + f = _svOpenFile(testfile); + _svGetValue_check(f, "TYPE", "InfiniBand"); + _svGetValue_check(f, "DEVICETYPE", "TeamPort"); + _svGetValue_check(f, "TEAM_PORT_CONFIG", expected_config); + _svGetValue_check(f, "TEAM_MASTER", "team0"); + svCloseFile(f); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +static void +test_read_team_port_empty_config(void) +{ + NMConnection * connection; + NMSettingConnection *s_con; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-team-port-empty-config", + NULL, + TYPE_ETHERNET, + NULL); + + s_con = nm_connection_get_setting_connection(connection); + g_assert(s_con); + g_assert_cmpstr(nm_setting_connection_get_connection_type(s_con), + ==, + NM_SETTING_WIRED_SETTING_NAME); + g_assert_cmpstr(nm_setting_connection_get_master(s_con), ==, "team0"); + + /* Normalization adds a team-port setting */ + g_assert(nm_connection_get_setting_team_port(connection)); + + /* empty/missing config */ + g_assert(!nm_setting_team_port_get_config(nm_connection_get_setting_team_port(connection))); + + g_object_unref(connection); +} + +static void +test_team_reread_slave(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection_1 = NULL; + gs_unref_object NMConnection *connection_2 = NULL; + gs_unref_object NMConnection *reread = NULL; + gboolean reread_same = FALSE; + NMSettingConnection * s_con; + + connection_1 = + nmtst_create_connection_from_keyfile("[connection]\n" + "id=team-slave-enp31s0f1-142\n" + "uuid=74f435bb-ede4-415a-9d48-f580b60eba04\n" + "type=vlan\n" + "autoconnect=false\n" + "interface-name=enp31s0f1-142\n" + "master=team142\n" + "permissions=\n" + "slave-type=team\n" + "\n" + "[vlan]\n" + "egress-priority-map=\n" + "flags=1\n" + "id=142\n" + "ingress-priority-map=\n" + "parent=enp31s0f1\n", + "/test_team_reread_slave"); + + /* to double-check keyfile syntax, re-create the connection by hand. */ + connection_2 = nmtst_create_minimal_connection("team-slave-enp31s0f1-142", + "74f435bb-ede4-415a-9d48-f580b60eba04", + NM_SETTING_VLAN_SETTING_NAME, + &s_con); + g_object_set(s_con, + NM_SETTING_CONNECTION_AUTOCONNECT, + FALSE, + NM_SETTING_CONNECTION_INTERFACE_NAME, + "enp31s0f1-142", + NM_SETTING_CONNECTION_MASTER, + "team142", + NM_SETTING_CONNECTION_SLAVE_TYPE, + "team", + NULL); + g_object_set(nm_connection_get_setting_vlan(connection_2), + NM_SETTING_VLAN_FLAGS, + 1, + NM_SETTING_VLAN_ID, + 142, + NM_SETTING_VLAN_PARENT, + "enp31s0f1", + NULL); + nm_connection_add_setting(connection_2, nm_setting_team_port_new()); + nmtst_connection_normalize(connection_2); + + nmtst_assert_connection_equals(connection_1, FALSE, connection_2, FALSE); + + _writer_new_connection_reread((nmtst_get_rand_uint32() % 2) ? connection_1 : connection_2, + TEST_SCRATCH_DIR, + &testfile, + TEST_IFCFG_DIR "/ifcfg-team-slave-enp31s0f1-142.cexpected", + &reread, + &reread_same); + _assert_reread_same((nmtst_get_rand_uint32() % 2) ? connection_1 : connection_2, reread); + g_assert(reread_same); + g_clear_object(&reread); + + reread = _connection_from_file(testfile, NULL, TYPE_VLAN, NULL); + nmtst_assert_connection_equals((nmtst_get_rand_uint32() % 2) ? connection_1 : connection_2, + FALSE, + reread, + FALSE); +} + +static void +test_read_proxy_basic(void) +{ + NMConnection * connection; + NMSettingProxy *s_proxy; + + /* Test basic proxy configuration */ + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-read-proxy-basic", + NULL, + TYPE_ETHERNET, + NULL); + + /* ===== Proxy setting ===== */ + s_proxy = nm_connection_get_setting_proxy(connection); + g_assert(s_proxy); + + /* Proxy method */ + g_assert_cmpint(nm_setting_proxy_get_method(s_proxy), ==, NM_SETTING_PROXY_METHOD_AUTO); + g_assert(nm_setting_proxy_get_browser_only(s_proxy)); + g_assert_cmpstr(nm_setting_proxy_get_pac_url(s_proxy), + ==, + "http://wpad.mycompany.com/wpad.dat"); + + g_object_unref(connection); +} + +static void +test_write_proxy_basic(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingWired * s_wired; + NMSettingProxy * s_proxy; + const char * expected_url = "https://wpad.neverland.org/wpad.dat"; + shvarFile * f; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write Proxy Basic", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRED_SETTING_NAME, + NULL); + + /* Proxy setting */ + s_proxy = (NMSettingProxy *) nm_setting_proxy_new(); + nm_connection_add_setting(connection, NM_SETTING(s_proxy)); + g_object_set(s_proxy, NM_SETTING_PROXY_METHOD, NM_SETTING_PROXY_METHOD_AUTO, NULL); + g_object_set(s_proxy, NM_SETTING_PROXY_PAC_URL, expected_url, NULL); + + /* Wired setting */ + s_wired = (NMSettingWired *) nm_setting_wired_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wired)); + + nmtst_assert_connection_verifies(connection); + + _writer_new_connec_exp(connection, + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR "/ifcfg-Test_Write_Proxy_Basic.cexpected", + &testfile); + + f = _svOpenFile(testfile); + _svGetValue_check(f, "TYPE", "Ethernet"); + _svGetValue_check(f, "PROXY_METHOD", "auto"); + _svGetValue_check(f, "PAC_URL", expected_url); + svCloseFile(f); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +/*****************************************************************************/ + +static const char * +_svUnescape(const char *str, char **to_free) +{ + const char * s; + gs_free char *str_free = NULL; + + g_assert(str); + g_assert(to_free); + + if (str[0] == '\0') { + /* avoid static string "" */ + str = (str_free = g_strdup(str)); + } + + s = svUnescape(str, to_free); + if (*to_free) { + g_assert(s == *to_free); + g_assert(s[0]); + } else { + g_assert(s == NULL || (!s[0] && (s < str || s > strchr(str, '\0'))) + || (s[0] && s >= str && s <= strchr(str, '\0'))); + } + return s; +} + +typedef struct { + const char *val; + const char *exp; + bool can_concat : 1; + bool needs_ascii_separator : 1; +} UnescapeTestData; + +static void +do_svUnescape_assert(const char *str, const char *expected) +{ + gs_free char *to_free = NULL; + const char * s; + + s = _svUnescape(str, &to_free); + g_assert_cmpstr(s, ==, expected); + + /* check we can make a round-trip */ + if (expected) { + gs_free char *s1_free = NULL; + gs_free char *s2_free = NULL; + const char * s1, *s2; + + s1 = svEscape(expected, &s1_free); + g_assert(s1); + + s2 = _svUnescape(s1, &s2_free); + g_assert(s2); + + g_assert_cmpstr(s2, ==, expected); + } +} + +static void +do_svUnescape_combine_ansi_append(GString * str_val, + GString * str_exp, + const UnescapeTestData *data, + gboolean honor_needs_ascii_separator) +{ + g_string_append(str_val, data->val); + g_string_append(str_exp, data->exp); + if (honor_needs_ascii_separator && data->needs_ascii_separator) { + /* the string has an open escape sequence. We must ensure that when + * combining it with another sequence, that they don't merge into + * something different. for example "\xa" + "a" must not result in + * "\xaa". Instead, we add a space in between to get "\xa a". */ + g_string_append(str_val, " "); + g_string_append(str_exp, " "); + } +} + +static void +do_svUnescape_combine_ansi(GString * str_val, + GString * str_exp, + const UnescapeTestData *data_ansi, + gsize data_len, + gssize idx) +{ + gsize i, j; + + g_string_set_size(str_val, 0); + g_string_set_size(str_exp, 0); + g_string_append(str_val, "$'"); + if (idx < 0) { + for (i = -idx; i > 0; i--) { + j = nmtst_get_rand_uint32() % data_len; + if (!data_ansi[j].can_concat) { + i++; + continue; + } + do_svUnescape_combine_ansi_append(str_val, str_exp, &data_ansi[j], i > 1); + } + } else { + g_assert_cmpint(idx, <, data_len); + do_svUnescape_combine_ansi_append(str_val, str_exp, &data_ansi[idx], FALSE); + } + g_string_append(str_val, "'"); +} + +static void +test_svUnescape(void) +{ +#define V0(v_value, v_expected) \ + { \ + .val = "" v_value "", .exp = v_expected, .can_concat = FALSE, \ + } +#define V1(v_value, v_expected) \ + { \ + .val = "" v_value "", .exp = v_expected, .can_concat = !!v_expected, \ + } +#define V2(v_value, v_expected) \ + { \ + .val = "" v_value "", .exp = v_expected, .can_concat = TRUE, \ + .needs_ascii_separator = TRUE, \ + } + const UnescapeTestData data_full[] = { + V1("", ""), + V0("'", NULL), + V1("'x'", "x"), + V1("' '", " "), + V1("'x'", "x"), + V0("\"", NULL), + V0("\\", NULL), + V0(" ", ""), + V0(" ", ""), + V0("a; #", "a"), + V0(" ; #", ""), + V0("; ", ""), + V0("; ;", NULL), + V0(" ; a #", NULL), + V0(" ; a;; #", NULL), + V0("a; ; #", NULL), + V0("\t # ", ""), + V0("\t #a", ""), + V0("\t #a\r", ""), + V0("\r", ""), + V1("\\\"", "\""), + V1("\\`", "`"), + V1("\\$", "$"), + V1("\\\\", "\\"), + V1("\\a", "a"), + V1("\\b", "b"), + V1("\\'", "'"), + V1("\\~", "~"), + V1("\\\t", "\t"), + V1("\"\\\"\"", "\""), + V1("\"\\`\"", "`"), + V1("\"\\$\"", "$"), + V1("\"\\\\\"", "\\"), + V1("\"\\a\"", "\\a"), + V1("\"\\b\"", "\\b"), + V1("\"\\\t\"", "\\\t"), + V0("ab\r", "ab"), + V0("a'b'\r ", "ab"), + V0("a'b' \r", "ab"), + V0("a#b", "a#b"), + V0("#b", "#b"), + V1("\'some string\'", "some string"), + V0("Bob outside LAN", NULL), + V1("x", "x"), + V1("'{ \"device\": \"team0\", \"link_watch\": { \"name\": \"ethtool\" } }'", + "{ \"device\": \"team0\", \"link_watch\": { \"name\": \"ethtool\" } }"), + V1("'{\"device\": \"team0\", \"link_watch\": {\"name\": \"ethtool\"}}'", + "{\"device\": \"team0\", \"link_watch\": {\"name\": \"ethtool\"}}"), + V1("x\"\"b", "xb"), + V1("x\"c\"b", "xcb"), + V1("\"c\"b", "cb"), + V1("\"c\"\\'b", "c'b"), + V1("$''", ""), + V1("$'\\n'", "\n"), + V0("$'\\'", NULL), + V1("$'\\x'", "\\x"), + V1("$'\\xa'", "\xa"), + V0("$'\\x0'", ""), + V1("$'\\x12'", "\x12"), + V1("$'\\x12A'", + "\x12" + "A"), + V1("$'\\x12t'", "\x12t"), + V1("\"aa\\\"\"", "aa\""), + V1("\"aa\\\"b\"c", "aa\"bc"), + V1("\"aa\\\"\"b", "aa\"b"), + + /* the following is not shell behavior, but kept for backward compatibility + * with old svEscape(). */ + V0("\"\\'\"", "'"), + V0("\"\\~\"", "~"), + V0("\"b\\~b\"", "b~b"), + V0("\"\\~\\~\"", "~~"), + V0("\"\\~\\'\"", "~'"), + + /* the following is shell-behavior, because it doesn't look like written + * by old svEscape(). */ + V1("\"\\~~\"", "\\~~"), + V1("\"\\a\\'\"", "\\a\\'"), + V1("x\"\\~\"", "x\\~"), + V1("\"\\'\"''", "\\'"), + V0("\"b\\~b\" ", "b\\~b"), + V1("\"b\\~b\"x", "b\\~bx"), + }; + const UnescapeTestData data_ansi[] = { + /* strings inside $''. They cannot be compared directly, but must + * be wrapped by do_svUnescape_combine_ansi(). */ + V1("", ""), + V1("a", "a"), + V1("b", "b"), + V1("x", "x"), + V1(" ", " "), + V1("\\a", "\a"), + V1("\\b", "\b"), + V1("\\e", "\e"), + V1("\\E", "\E"), + V1("\\f", "\f"), + V1("\\n", "\n"), + V1("\\r", "\r"), + V1("\\t", "\t"), + V1("\\v", "\v"), + V1("\\\\", "\\"), + V1("\\'", "'"), + V1("\\\"", "\""), + V1("\\?", "\?"), + V1("\\?", "?"), + V2("\\8", "\\8"), + V2("\\1", "\1"), + V1("\\1A", "\1A"), + V1("\\18", "\18"), + V2("\\01", "\1"), + V1("\\001", "\1"), + V0("\\008", ""), + V1("\\018", "\0018"), + V0("\\08", ""), + V1("\\18", "\0018"), + V1("\\x", "\\x"), + V2("\\xa", "\xa"), + V1("\\x12", "\x12"), + V1("\\x12A", + "\x12" + "A"), + V1("\\x12a", + "\x12" + "a"), + V1("\\x12t", "\x12t"), + V1("\\x1a", "\x1a"), + V1("\\x1A", "\x1A"), + V1("\\ut", "\\ut"), + V2("\\ua", "\xa"), + V1("\\uat", "\xat"), + V2("\\uab", "\xc2\xab"), + V1("\\uabt", "\xc2\xabt"), + V2("\\uabc", "\xe0\xaa\xbc"), + V1("\\uabct", "\xe0\xaa\xbct"), + V2("\\uabcd", "\xea\xaf\x8d"), + V1("\\uabcdt", "\xea\xaf\x8dt"), + V2("\\uabcde", + "\xea\xaf\x8d" + "e"), + V1("\\uabcdet", + "\xea\xaf\x8d" + "et"), + V1("\\Ut", "\\Ut"), + V2("\\Ua", "\xa"), + V1("\\Uat", "\xat"), + V2("\\Uab", "\xc2\xab"), + V1("\\Uabt", "\xc2\xabt"), + V2("\\Uabc", "\xe0\xaa\xbc"), + V1("\\Uabct", "\xe0\xaa\xbct"), + V2("\\Uabcd", "\xea\xaf\x8d"), + V1("\\Uabcdt", "\xea\xaf\x8dt"), + V2("\\Uabcde", "\xf2\xab\xb3\x9e"), + V1("\\Uabcdet", "\xf2\xab\xb3\x9et"), + V2("\\Uabcde0", "\xf8\xaa\xbc\xb7\xa0"), + V1("\\Uabcde0t", "\xf8\xaa\xbc\xb7\xa0t"), + V2("\\Uabcde01", "\xfc\x8a\xaf\x8d\xb8\x81"), + V1("\\Uabcde01t", "\xfc\x8a\xaf\x8d\xb8\x81t"), + V2("\\U0abcde01", "\xfc\x8a\xaf\x8d\xb8\x81"), + V1("\\U0abcde01t", "\xfc\x8a\xaf\x8d\xb8\x81t"), + V1("\\U00abcde01", + "\xf8\xaa\xbc\xb7\xa0" + "1"), + V1("\\U00abcde01t", + "\xf8\xaa\xbc\xb7\xa0" + "1t"), + + /* control-x sequence is not supported */ + V1("\\c", "\\c"), + V1("\\c1", "\\c1"), + }; +#undef V0 +#undef V1 +#undef V2 + gsize i; + nm_auto_free_gstring GString *str_val = g_string_new(NULL); + nm_auto_free_gstring GString *str_val2 = g_string_new(NULL); + nm_auto_free_gstring GString *str_exp = g_string_new(NULL); + nm_auto_free_gstring GString *str_exp2 = g_string_new(NULL); + + do_svUnescape_assert("' '' '", " "); + + for (i = 0; i < G_N_ELEMENTS(data_full); i++) + do_svUnescape_assert(data_full[i].val, data_full[i].exp); + + for (i = 0; i < G_N_ELEMENTS(data_ansi); i++) { + do_svUnescape_combine_ansi(str_val, str_exp, data_ansi, G_N_ELEMENTS(data_ansi), i); + do_svUnescape_assert(str_val->str, str_exp->str); + } + + /* different values can be just concatenated... */ + for (i = 0; i < 200; i++) { + gsize num_concat = (nmtst_get_rand_uint32() % 5) + 2; + + g_string_set_size(str_val, 0); + g_string_set_size(str_exp, 0); + + while (num_concat > 0) { + gsize idx; + + if ((nmtst_get_rand_uint32() % 3 == 0)) { + do_svUnescape_combine_ansi(str_val2, + str_exp2, + data_ansi, + G_N_ELEMENTS(data_ansi), + -((int) ((nmtst_get_rand_uint32() % 5) + 1))); + continue; + } + + idx = nmtst_get_rand_uint32() % G_N_ELEMENTS(data_full); + if (!data_full[idx].can_concat) + continue; + g_string_append(str_val, data_full[idx].val); + g_string_append(str_exp, data_full[idx].exp); + num_concat--; + } + + switch (nmtst_get_rand_uint32() % 3) { + case 0: + g_string_append(str_val, " "); + break; + case 1: + g_string_append(str_val, " "); + break; + } + switch (nmtst_get_rand_uint32() % 3) { + case 0: + g_string_append(str_val, " #"); + break; + case 1: + g_string_append(str_val, " #foo"); + break; + } + do_svUnescape_assert(str_val->str, str_exp->str); + } +} + +/*****************************************************************************/ + +static void +test_write_unknown(gconstpointer test_data) +{ + nmtst_auto_unlinkfile char *filename_tmp_1 = g_strdup(TEST_SCRATCH_DIR_TMP "/tmp-1"); + const char * testfile = test_data; + gs_free char * testfile_expected = g_strconcat(testfile, ".expected", NULL); + shvarFile * sv; + gs_free_error GError *error = NULL; + gboolean success; + gs_free char * file_contents_out = NULL; + gs_free char * file_contents_exp = NULL; + + sv = _svOpenFile(testfile); + + _nmtst_svFileSetName(sv, filename_tmp_1); + _nmtst_svFileSetModified(sv); + + if (g_str_has_suffix(testfile, "ifcfg-test-write-unknown-4")) { + _svGetValue_check(sv, "IPADDR", "l4x"); + _svGetValue_check(sv, "IPADDR2", ""); + _svGetValue_check(sv, "IPADDR3", "name3-value"); + + svSetValue(sv, "IPADDR", "set-by-test1"); + svSetValue(sv, "IPADDR2", NULL); + svSetValue(sv, "IPADDR2", "set-by-test2"); + svSetValue(sv, "IPADDR3", "set-by-test3"); + + _svGetValue_check(sv, "METRIC", NULL); + _svGetValue_check(sv, "METRIC1", ""); + _svGetValue_check(sv, "METRIC2", ""); + _svGetValue_check(sv, "METRIC3", "x"); + + _svGetValue_check(sv, "IPADDR", "set-by-test1"); + _svGetValue_check(sv, "IPADDR2", "set-by-test2"); + _svGetValue_check(sv, "IPADDR3", "set-by-test3"); + } + + success = svWriteFile(sv, 0644, &error); + nmtst_assert_success(success, error); + + file_contents_out = nmtst_file_get_contents(filename_tmp_1); + file_contents_exp = nmtst_file_get_contents(testfile_expected); + + g_assert_cmpstr(file_contents_out, ==, file_contents_exp); + + svCloseFile(sv); +} + +/*****************************************************************************/ + +static void +test_read_vlan_trailing_spaces(void) +{ + const char * testfile = TEST_IFCFG_DIR "/ifcfg-test-vlan-trailing-spaces"; + NMConnection * connection; + gboolean success; + GError * error = NULL; + NMSettingVlan *s_vlan; + char * contents = NULL; + + /* Ensure there is whitespace at the end of the VLAN interface name, + * to prevent the whitespace getting stripped off and committed mistakenly + * by something in the future. + */ + success = g_file_get_contents(testfile, &contents, NULL, &error); + g_assert_no_error(error); + g_assert(success); + g_assert(contents && contents[0]); + g_assert(strstr(contents, "DEVICE=\"vlan201\" \n")); + g_free(contents); + + connection = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + + s_vlan = nm_connection_get_setting_vlan(connection); + g_assert(s_vlan); + + g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "vlan201"); + g_assert_cmpstr(nm_setting_vlan_get_parent(s_vlan), ==, "enccw0.0.fb00"); + g_assert_cmpint(nm_setting_vlan_get_id(s_vlan), ==, 201); + g_assert_cmpint(nm_setting_vlan_get_flags(s_vlan), ==, NM_VLAN_FLAG_REORDER_HEADERS); + + g_object_unref(connection); +} + +/*****************************************************************************/ + +static void +test_sit_read_ignore(void) +{ + gs_free_error GError *error = NULL; + + _connection_from_file_fail(TEST_IFCFG_DIR "/ifcfg-test-sit-ignore", + NULL, + TYPE_ETHERNET, + &error); + nmtst_assert_error(error, 0, 0, "*Ignoring unsupported connection due to IPV6TUNNELIPV4*"); +} + +/*****************************************************************************/ + +static void +do_test_utils_name(const char *desc, const char *path, gboolean only_ifcfg, const char *expected) +{ + const char *result; + + result = utils_get_ifcfg_name(path, only_ifcfg); + g_assert_cmpstr(result, ==, expected); +} + +static void +test_utils_name(void) +{ + do_test_utils_name("get-ifcfg-name-bad", "/foo/bar/adfasdfadf", FALSE, NULL); + do_test_utils_name("get-ifcfg-name-good", "/foo/bar/ifcfg-FooBar", FALSE, "FooBar"); + do_test_utils_name("get-ifcfg-name-keys", "/foo/bar/keys-BlahLbah", FALSE, "BlahLbah"); + do_test_utils_name("get-ifcfg-name-route", "/foo/bar/route-Lalalala", FALSE, "Lalalala"); + do_test_utils_name("get-ifcfg-name-only-ifcfg-route", "/foo/bar/route-Lalalala", TRUE, NULL); + do_test_utils_name("get-ifcfg-name-only-ifcfg-keys", "/foo/bar/keys-Lalalala", TRUE, NULL); + do_test_utils_name("get-ifcfg-name-no-path-ifcfg", "ifcfg-Lalalala", FALSE, "Lalalala"); + do_test_utils_name("get-ifcfg-name-no-path-keys", "keys-Lalalala", FALSE, "Lalalala"); + do_test_utils_name("get-ifcfg-name-no-path-route", "route-Lalalala", FALSE, "Lalalala"); + + do_test_utils_name("get-ifcfg-name-bad2-ifcfg", "/foo/bar/asdfasifcfg-Foobar", FALSE, NULL); + do_test_utils_name("get-ifcfg-name-bad2-keys", "/foo/bar/asdfaskeys-Foobar", FALSE, NULL); + do_test_utils_name("get-ifcfg-name-bad2-route", "/foo/bar/asdfasroute-Foobar", FALSE, NULL); +} + +/*****************************************************************************/ + +static void +do_test_utils_path_ifcfg(const char *desc, const char *path, const char *expected) +{ + char *result; + + result = utils_get_ifcfg_path(path); + g_assert_cmpstr(result, ==, expected); + g_free(result); +} + +static void +do_test_utils_path_keys(const char *desc, const char *path, const char *expected) +{ + char *result; + + result = utils_get_keys_path(path); + g_assert_cmpstr(result, ==, expected); + g_free(result); +} + +static void +do_test_utils_path_route(const char *desc, const char *path, const char *expected) +{ + char *result; + + result = utils_get_route_path(path); + g_assert_cmpstr(result, ==, expected); + g_free(result); +} + +static void +test_utils_path(void) +{ + do_test_utils_path_ifcfg("ifcfg-path-bad", "/foo/bar/adfasdfasdf", NULL); + do_test_utils_path_ifcfg("ifcfg-path-from-keys-no-path", "keys-BlahBlah", "ifcfg-BlahBlah"); + do_test_utils_path_ifcfg("ifcfg-path-from-keys", + "/foo/bar/keys-BlahBlah", + "/foo/bar/ifcfg-BlahBlah"); + do_test_utils_path_ifcfg("ifcfg-path-from-route", + "/foo/bar/route-BlahBlah", + "/foo/bar/ifcfg-BlahBlah"); + + do_test_utils_path_keys("keys-path-bad", "/foo/bar/asdfasdfasdfasdf", NULL); + do_test_utils_path_keys("keys-path-from-ifcfg-no-path", "ifcfg-FooBar", "keys-FooBar"); + do_test_utils_path_keys("keys-path-from-ifcfg", + "/foo/bar/ifcfg-FooBar", + "/foo/bar/keys-FooBar"); + do_test_utils_path_keys("keys-path-from-route", + "/foo/bar/route-FooBar", + "/foo/bar/keys-FooBar"); + + do_test_utils_path_route("route-path-bad", "/foo/bar/asdfasdfasdfasdf", NULL); + do_test_utils_path_route("route-path-from-ifcfg-no-path", "ifcfg-FooBar", "route-FooBar"); + do_test_utils_path_route("route-path-from-ifcfg", + "/foo/bar/ifcfg-FooBar", + "/foo/bar/route-FooBar"); + do_test_utils_path_route("route-path-from-keys", + "/foo/bar/keys-FooBar", + "/foo/bar/route-FooBar"); +} + +/*****************************************************************************/ + +static void +do_test_utils_ignored(const char *desc, const char *path, gboolean expected_ignored) +{ + gboolean result; + + result = utils_should_ignore_file(path, FALSE); + g_assert(result == expected_ignored); +} + +static void +test_utils_ignore(void) +{ + do_test_utils_ignored("ignored-ifcfg", "ifcfg-FooBar", FALSE); + do_test_utils_ignored("ignored-keys", "keys-FooBar", FALSE); + do_test_utils_ignored("ignored-route", "route-FooBar", FALSE); + do_test_utils_ignored("ignored-bak", "ifcfg-FooBar" BAK_TAG, TRUE); + do_test_utils_ignored("ignored-tilde", "ifcfg-FooBar" TILDE_TAG, TRUE); + do_test_utils_ignored("ignored-orig", "ifcfg-FooBar" ORIG_TAG, TRUE); + do_test_utils_ignored("ignored-rej", "ifcfg-FooBar" REJ_TAG, TRUE); + do_test_utils_ignored("ignored-rpmnew", "ifcfg-FooBar" RPMNEW_TAG, TRUE); + do_test_utils_ignored("ignored-augnew", "ifcfg-FooBar" AUGNEW_TAG, TRUE); + do_test_utils_ignored("ignored-augtmp", "ifcfg-FooBar" AUGTMP_TAG, TRUE); +} + +/*****************************************************************************/ + +static void +test_sriov_read(void) +{ + gs_unref_object NMConnection *connection = NULL; + NMSettingSriov * s_sriov; + NMSriovVF * vf; + GVariant * variant; + GError * error = NULL; + char * str; + + connection = + _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-sriov", NULL, TYPE_ETHERNET, NULL); + + g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "eth0"); + + s_sriov = NM_SETTING_SRIOV(nm_connection_get_setting(connection, NM_TYPE_SETTING_SRIOV)); + g_assert(s_sriov); + + g_assert_cmpint(nm_setting_sriov_get_total_vfs(s_sriov), ==, 16); + g_assert_cmpint(nm_setting_sriov_get_num_vfs(s_sriov), ==, 3); + g_assert_cmpint(nm_setting_sriov_get_autoprobe_drivers(s_sriov), ==, NM_TERNARY_FALSE); + + /* VF 3 */ + vf = nm_setting_sriov_get_vf(s_sriov, 0); + g_assert(vf); + g_assert_cmpint(nm_sriov_vf_get_index(vf), ==, 3); + + variant = nm_sriov_vf_get_attribute(vf, NM_SRIOV_VF_ATTRIBUTE_MAC); + g_assert(variant); + g_assert(g_variant_is_of_type(variant, G_VARIANT_TYPE_STRING)); + g_assert_cmpstr(g_variant_get_string(variant, NULL), ==, "55:44:33:22:11:00"); + + variant = nm_sriov_vf_get_attribute(vf, NM_SRIOV_VF_ATTRIBUTE_SPOOF_CHECK); + g_assert(variant); + g_assert(g_variant_is_of_type(variant, G_VARIANT_TYPE_BOOLEAN)); + g_assert_cmpint(g_variant_get_boolean(variant), ==, TRUE); + + /* VF 12 */ + vf = nm_setting_sriov_get_vf(s_sriov, 1); + str = nm_utils_sriov_vf_to_str(vf, FALSE, &error); + g_assert_no_error(error); + g_assert_cmpstr(str, ==, "12 min-tx-rate=100 trust=false vlans=1.200.ad"); + g_free(str); + + /* VF 15 */ + vf = nm_setting_sriov_get_vf(s_sriov, 2); + str = nm_utils_sriov_vf_to_str(vf, FALSE, &error); + g_assert_no_error(error); + g_assert_cmpstr(str, ==, "15 mac=01:23:45:67:89:ab max-tx-rate=200 vlans=2"); + g_free(str); +} + +static void +test_sriov_write(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + NMSettingWired * s_wired; + NMSettingSriov * s_sriov; + NMSriovVF * vf; + gs_unref_ptrarray GPtrArray *vfs = NULL; + NMIPAddress * addr; + GError * error = NULL; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write SR-IOV config", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_INTERFACE_NAME, + "eth0", + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRED_SETTING_NAME, + NULL); + + /* Wired setting */ + s_wired = (NMSettingWired *) nm_setting_wired_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wired)); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP4_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_GATEWAY, + "1.1.1.1", + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NULL); + + addr = nm_ip_address_new(AF_INET, "1.1.1.3", 24, &error); + g_assert_no_error(error); + nm_setting_ip_config_add_address(s_ip4, addr); + nm_ip_address_unref(addr); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NULL); + + /* SRIOV setting */ + s_sriov = (NMSettingSriov *) nm_setting_sriov_new(); + nm_connection_add_setting(connection, NM_SETTING(s_sriov)); + + vfs = g_ptr_array_new_with_free_func((GDestroyNotify) nm_sriov_vf_unref); + + vf = nm_utils_sriov_vf_from_str("2 mac=55:55:55:55:55:55 vlans=3.10.ad;10", &error); + nmtst_assert_success(vf, error); + g_ptr_array_add(vfs, vf); + + vf = nm_utils_sriov_vf_from_str("19 spoof-check=true", &error); + nmtst_assert_success(vf, error); + g_ptr_array_add(vfs, vf); + + g_object_set(s_sriov, + NM_SETTING_SRIOV_TOTAL_VFS, + 64, + NM_SETTING_SRIOV_VFS, + vfs, + NM_SETTING_SRIOV_AUTOPROBE_DRIVERS, + NM_TERNARY_TRUE, + NULL); + + nm_connection_add_setting(connection, nm_setting_proxy_new()); + + nmtst_assert_connection_verifies_without_normalization(connection); + + _writer_new_connec_exp(connection, + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR "/ifcfg-test-sriov-write.cexpected", + &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_ETHERNET, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +/*****************************************************************************/ + +static void +test_tc_read(void) +{ + NMConnection * connection; + NMSettingTCConfig *s_tc; + NMTCQdisc * qdisc; + NMTCTfilter * filter; + char * str; + + connection = _connection_from_file(TEST_IFCFG_DIR "/ifcfg-test-tc", NULL, TYPE_ETHERNET, NULL); + + g_assert_cmpstr(nm_connection_get_interface_name(connection), ==, "eth0"); + + s_tc = nm_connection_get_setting_tc_config(connection); + g_assert(s_tc); + + g_assert_cmpint(nm_setting_tc_config_get_num_qdiscs(s_tc), ==, 1); + qdisc = nm_setting_tc_config_get_qdisc(s_tc, 0); + g_assert(qdisc); + g_assert_cmpint(nm_tc_qdisc_get_parent(qdisc), ==, TC_H_ROOT); + g_assert_cmpint(nm_tc_qdisc_get_handle(qdisc), ==, TC_H_UNSPEC); + g_assert_cmpstr(nm_tc_qdisc_get_kind(qdisc), ==, "fq_codel"); + + g_assert_cmpint(nm_setting_tc_config_get_num_tfilters(s_tc), ==, 1); + filter = nm_setting_tc_config_get_tfilter(s_tc, 0); + g_assert(filter); + str = nm_utils_tc_tfilter_to_str(filter, NULL); + g_assert_cmpstr(str, ==, "parent 1234: matchall action simple sdata Hello"); + g_free(str); + + g_object_unref(connection); +} + +static void +test_tc_write(void) +{ + nmtst_auto_unlinkfile char *testfile = NULL; + gs_unref_object NMConnection *connection = NULL; + gs_unref_object NMConnection *reread = NULL; + NMSettingConnection * s_con; + NMSettingIPConfig * s_ip4; + NMSettingIPConfig * s_ip6; + NMSettingWired * s_wired; + NMSettingTCConfig * s_tc; + NMTCQdisc * qdisc; + NMTCTfilter * tfilter; + NMIPAddress * addr; + GError * error = NULL; + + connection = nm_simple_connection_new(); + + /* Connection setting */ + s_con = (NMSettingConnection *) nm_setting_connection_new(); + nm_connection_add_setting(connection, NM_SETTING(s_con)); + + g_object_set(s_con, + NM_SETTING_CONNECTION_ID, + "Test Write TC config", + NM_SETTING_CONNECTION_UUID, + nm_utils_uuid_generate_a(), + NM_SETTING_CONNECTION_AUTOCONNECT, + TRUE, + NM_SETTING_CONNECTION_INTERFACE_NAME, + "eth0", + NM_SETTING_CONNECTION_TYPE, + NM_SETTING_WIRED_SETTING_NAME, + NULL); + + /* Wired setting */ + s_wired = (NMSettingWired *) nm_setting_wired_new(); + nm_connection_add_setting(connection, NM_SETTING(s_wired)); + + /* IP4 setting */ + s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip4)); + + g_object_set(s_ip4, + NM_SETTING_IP_CONFIG_METHOD, + NM_SETTING_IP4_CONFIG_METHOD_MANUAL, + NM_SETTING_IP_CONFIG_GATEWAY, + "1.1.1.1", + NM_SETTING_IP_CONFIG_MAY_FAIL, + TRUE, + NULL); + + addr = nm_ip_address_new(AF_INET, "1.1.1.3", 24, &error); + g_assert_no_error(error); + nm_setting_ip_config_add_address(s_ip4, addr); + nm_ip_address_unref(addr); + + /* IP6 setting */ + s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_ip6)); + + g_object_set(s_ip6, NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NULL); + + /* TC setting */ + s_tc = (NMSettingTCConfig *) nm_setting_tc_config_new(); + nm_connection_add_setting(connection, NM_SETTING(s_tc)); + + qdisc = nm_tc_qdisc_new("pfifo_fast", TC_H_MAKE(0x2468 << 16, 0x2), &error); + g_assert_no_error(error); + nm_setting_tc_config_add_qdisc(s_tc, qdisc); + nm_tc_qdisc_unref(qdisc); + + tfilter = + nm_utils_tc_tfilter_from_str("parent 1234: matchall action simple sdata Hello", &error); + g_assert_no_error(error); + nm_setting_tc_config_add_tfilter(s_tc, tfilter); + nm_tc_tfilter_unref(tfilter); + + nm_connection_add_setting(connection, nm_setting_proxy_new()); + + nmtst_assert_connection_verifies_without_normalization(connection); + + _writer_new_connec_exp(connection, + TEST_SCRATCH_DIR, + TEST_IFCFG_DIR "/ifcfg-test-tc-write.cexpected", + &testfile); + + reread = _connection_from_file(testfile, NULL, TYPE_BOND, NULL); + + nmtst_assert_connection_equals(connection, TRUE, reread, FALSE); +} + +/*****************************************************************************/ + +static void +test_well_known_keys(void) +{ + gsize i; + + for (i = 0; i < G_N_ELEMENTS(nms_ifcfg_well_known_keys); i++) { + const NMSIfcfgKeyTypeInfo *ti = &nms_ifcfg_well_known_keys[i]; + + g_assert(ti->key_name); + g_assert(ti->key_name[0]); + g_assert(NM_FLAGS_HAS(ti->key_flags, NMS_IFCFG_KEY_TYPE_WELL_KNOWN)); + g_assert( + nm_utils_is_power_of_two(ti->key_flags + & (NMS_IFCFG_KEY_TYPE_IS_PLAIN | NMS_IFCFG_KEY_TYPE_IS_NUMBERED + | NMS_IFCFG_KEY_TYPE_IS_PREFIX))); + } + + for (i = 1; i < G_N_ELEMENTS(nms_ifcfg_well_known_keys); i++) { + const NMSIfcfgKeyTypeInfo *ti_prev = &nms_ifcfg_well_known_keys[i - 1]; + const NMSIfcfgKeyTypeInfo *ti = &nms_ifcfg_well_known_keys[i]; + + g_assert_cmpstr(ti_prev->key_name, <, ti->key_name); + } + + for (i = 0; i < G_N_ELEMENTS(nms_ifcfg_well_known_keys); i++) { + const NMSIfcfgKeyTypeInfo *ti = &nms_ifcfg_well_known_keys[i]; + gs_free char * key_name = NULL; + gssize idx; + + g_assert(ti == nms_ifcfg_well_known_key_find_info(ti->key_name, &idx)); + g_assert_cmpint(i, ==, idx); + + key_name = g_strdup(ti->key_name); + g_assert(ti == nms_ifcfg_well_known_key_find_info(key_name, &idx)); + g_assert_cmpint(i, ==, idx); + } + +#define _test_well_known(key, expected) \ + G_STMT_START \ + { \ + const NMSIfcfgKeyTypeInfo *_ti; \ + const char * _expected = (expected); \ + \ + _ti = nms_ifcfg_rh_utils_is_well_known_key("" key ""); \ + if (!_expected) { \ + g_assert(!_ti); \ + } else { \ + g_assert(_ti); \ + g_assert_cmpstr(_ti->key_name, ==, _expected); \ + } \ + } \ + G_STMT_END + +#define _test_well_known_plain(key) _test_well_known("" key "", "" key "") + + _test_well_known_plain("ONBOOT"); + _test_well_known("NM_USER_", NULL); + _test_well_known("NM_USER_x", "NM_USER_"); + _test_well_known("IPADDR", "IPADDR"); + _test_well_known("IPADDR1", "IPADDR"); + _test_well_known("IPADDRx", NULL); +} + +/*****************************************************************************/ + +static void +_do_utils_has_route_file_new_syntax_size(gboolean has_new_syntax, + const char *content, + gssize content_len) +{ + nmtst_auto_unlinkfile char *testfile = + g_strdup(TEST_SCRATCH_DIR "/utils-has-route-file-new-syntax-test.txt"); + gboolean val; + + nmtst_file_set_contents_size(testfile, content, content_len); + + val = utils_has_route_file_new_syntax(testfile); + + g_assert_cmpint(val, ==, has_new_syntax); +} +#define _do_utils_has_route_file_new_syntax(has_new_syntax, content) \ + _do_utils_has_route_file_new_syntax_size(has_new_syntax, (content), NM_STRLEN(content)) + +static void +test_utils_has_route_file_new_syntax(void) +{ + _do_utils_has_route_file_new_syntax(TRUE, ""); + _do_utils_has_route_file_new_syntax(FALSE, "\0"); + _do_utils_has_route_file_new_syntax(FALSE, "\n"); + _do_utils_has_route_file_new_syntax(FALSE, "ADDRESS=bogus"); + _do_utils_has_route_file_new_syntax(FALSE, "ADDRESS=bogus\0"); + _do_utils_has_route_file_new_syntax(TRUE, "ADDRESS1=b\0ogus\0"); + _do_utils_has_route_file_new_syntax(TRUE, "ADDRESS1=bogus\0"); + _do_utils_has_route_file_new_syntax(TRUE, "\n\n\tADDRESS1=bogus\0"); + _do_utils_has_route_file_new_syntax(FALSE, "\n\n\tADDRESS=bogus\n"); + _do_utils_has_route_file_new_syntax(TRUE, "\n\n\tADDRESS=bogus\n ADDRESS000=\n"); + _do_utils_has_route_file_new_syntax(FALSE, "\n\n\tROUTE1=bogus\n ADDRES=\n"); + _do_utils_has_route_file_new_syntax(FALSE, "\n\n\tADDRESS=bogus\n ADDRESS\000000=\n"); +} + +/*****************************************************************************/ + +static void +test_ethtool_names(void) +{ + static const struct { + NMEthtoolID ethtool_id; + const char *kernel_name; + } kernel_names[] = { + {NM_ETHTOOL_ID_FEATURE_GRO, "rx-gro"}, + {NM_ETHTOOL_ID_FEATURE_GSO, "tx-generic-segmentation"}, + {NM_ETHTOOL_ID_FEATURE_LRO, "rx-lro"}, + {NM_ETHTOOL_ID_FEATURE_NTUPLE, "rx-ntuple-filter"}, + {NM_ETHTOOL_ID_FEATURE_RX, "rx-checksum"}, + {NM_ETHTOOL_ID_FEATURE_RXHASH, "rx-hashing"}, + {NM_ETHTOOL_ID_FEATURE_RXVLAN, "rx-vlan-hw-parse"}, + {NM_ETHTOOL_ID_FEATURE_TXVLAN, "tx-vlan-hw-insert"}, + }; + const struct { + guint nm_ethtool_id_first; + guint nm_ethtool_id_last; + } s_idxs[] = { + {_NM_ETHTOOL_ID_FEATURE_FIRST, _NM_ETHTOOL_ID_FEATURE_LAST}, + {_NM_ETHTOOL_ID_COALESCE_FIRST, _NM_ETHTOOL_ID_COALESCE_LAST}, + {_NM_ETHTOOL_ID_RING_FIRST, _NM_ETHTOOL_ID_RING_LAST}, + }; + const NMEthtoolData *data; + NMEthtoolID id; + guint i, k; + + for (k = 0; k < sizeof(s_idxs) / sizeof(*s_idxs); ++k) { + for (id = s_idxs[k].nm_ethtool_id_first; id <= s_idxs[k].nm_ethtool_id_last; id++) { + const char *ifcfg_rh_name; + + g_assert(id >= 0); + g_assert(id < G_N_ELEMENTS(_nm_ethtool_ifcfg_names)); + ifcfg_rh_name = _nm_ethtool_ifcfg_names[id]; + g_assert(ifcfg_rh_name && ifcfg_rh_name[0]); + + for (i = s_idxs[k].nm_ethtool_id_first; i < s_idxs[k].nm_ethtool_id_last; i++) { + if (i != id) + g_assert_cmpstr(ifcfg_rh_name, !=, _nm_ethtool_ifcfg_names[i]); + } + + g_assert_cmpstr(nms_ifcfg_rh_utils_get_ethtool_name(id), ==, ifcfg_rh_name); + + data = nms_ifcfg_rh_utils_get_ethtool_by_name(ifcfg_rh_name, nm_ethtool_id_to_type(id)); + + g_assert(data); + g_assert(data->id == id); + } + } + + for (i = 0; i < G_N_ELEMENTS(kernel_names); i++) { + const char *name = kernel_names[i].kernel_name; + + id = kernel_names[i].ethtool_id; + + data = nms_ifcfg_rh_utils_get_ethtool_by_name(name, nm_ethtool_id_to_type(id)); + + g_assert(data); + g_assert(data->id == id); + g_assert_cmpstr(nms_ifcfg_rh_utils_get_ethtool_name(id), !=, name); + } +} + +/*****************************************************************************/ + +#define TPATH "/settings/plugins/ifcfg-rh/" + +#define TEST_IFCFG_WIFI_OPEN_SSID_LONG_QUOTED \ + TEST_IFCFG_DIR "/ifcfg-test-wifi-open-ssid-long-quoted" +#define TEST_IFCFG_WIFI_OPEN_SSID_LONG_HEX TEST_IFCFG_DIR "/ifcfg-test-wifi-open-ssid-long-hex" + +#define DEFAULT_HEX_PSK "7d308b11df1b4243b0f78e5f3fc68cdbb9a264ed0edf4c188edf329ff5b467f0" + +NMTST_DEFINE(); + +int +main(int argc, char **argv) +{ + int errsv; + + nmtst_init_assert_logging(&argc, &argv, "INFO", "DEFAULT"); + + if (g_mkdir_with_parents(TEST_SCRATCH_DIR_TMP, 0755) != 0) { + errsv = errno; + g_error("failure to create test directory \"%s\": %s", + TEST_SCRATCH_DIR_TMP, + nm_strerror_native(errsv)); + } + + g_test_add_func(TPATH "svUnescape", test_svUnescape); + + g_test_add_data_func(TPATH "write-unknown/1", + TEST_IFCFG_DIR "/ifcfg-test-write-unknown-1", + test_write_unknown); + g_test_add_data_func(TPATH "write-unknown/2", + TEST_IFCFG_DIR "/ifcfg-test-write-unknown-2", + test_write_unknown); + g_test_add_data_func(TPATH "write-unknown/3", + TEST_IFCFG_DIR "/ifcfg-test-write-unknown-3", + test_write_unknown); + g_test_add_data_func(TPATH "write-unknown/4", + TEST_IFCFG_DIR "/ifcfg-test-write-unknown-4", + test_write_unknown); + + g_test_add_func(TPATH "vlan-trailing-spaces", test_read_vlan_trailing_spaces); + + g_test_add_func(TPATH "unmanaged", test_read_unmanaged); + g_test_add_func(TPATH "unmanaged-unrecognized", test_read_unmanaged_unrecognized); + g_test_add_func(TPATH "unrecognized", test_read_unrecognized); + g_test_add_func(TPATH "basic", test_read_basic); + g_test_add_func(TPATH "miscellaneous-variables", test_read_miscellaneous_variables); + g_test_add_func(TPATH "variables-corner-cases", test_read_variables_corner_cases); + g_test_add_data_func(TPATH "no-prefix/8", + GUINT_TO_POINTER(8), + test_read_wired_static_no_prefix); + g_test_add_data_func(TPATH "no-prefix/16", + GUINT_TO_POINTER(16), + test_read_wired_static_no_prefix); + g_test_add_data_func(TPATH "no-prefix/24", + GUINT_TO_POINTER(24), + test_read_wired_static_no_prefix); + g_test_add_data_func(TPATH "static-ip6-only-gw/_NULL_", + NULL, + test_write_wired_static_ip6_only_gw); + g_test_add_data_func(TPATH "static-ip6-only-gw/::", "::", test_write_wired_static_ip6_only_gw); + g_test_add_data_func(TPATH "static-ip6-only-gw/2001:db8:8:4::2", + "2001:db8:8:4::2", + test_write_wired_static_ip6_only_gw); + g_test_add_data_func(TPATH "static-ip6-only-gw/::ffff:255.255.255.255", + "::ffff:255.255.255.255", + test_write_wired_static_ip6_only_gw); + g_test_add_func(TPATH "ip6/disabled", test_write_ip6_disabled); + g_test_add_func(TPATH "read-dns-options", test_read_dns_options); + g_test_add_func(TPATH "clear-master", test_clear_master); + + nmtst_add_test_func(TPATH "read-static", + test_read_wired_static, + TEST_IFCFG_DIR "/ifcfg-test-wired-static", + "System test-wired-static", + GINT_TO_POINTER(TRUE)); + nmtst_add_test_func(TPATH "read-static-bootproto", + test_read_wired_static, + TEST_IFCFG_DIR "/ifcfg-test-wired-static-bootproto", + "System test-wired-static-bootproto", + GINT_TO_POINTER(FALSE)); + + g_test_add_func(TPATH "read-netmask-1", test_read_netmask_1); + + g_test_add_func(TPATH "read-dhcp", test_read_wired_dhcp); + g_test_add_func(TPATH "read-dhcp-plus-ip", test_read_wired_dhcp_plus_ip); + g_test_add_func(TPATH "read-shared-plus-ip", test_read_wired_shared_plus_ip); + g_test_add_func(TPATH "read-dhcp-send-hostname", test_read_write_wired_dhcp_send_hostname); + g_test_add_func(TPATH "read-dhcpv6-hostname-fallback", + test_read_wired_dhcpv6_hostname_fallback); + g_test_add_func(TPATH "read-global-gateway", test_read_wired_global_gateway); + g_test_add_func(TPATH "read-global-gateway-ignore", test_read_wired_global_gateway_ignore); + g_test_add_func(TPATH "read-obsolete-gateway-n", test_read_wired_obsolete_gateway_n); + g_test_add_func(TPATH "read-never-default", test_read_wired_never_default); + g_test_add_func(TPATH "read-defroute-no", test_read_wired_defroute_no); + g_test_add_func(TPATH "read-defroute-no-gatewaydev-yes", + test_read_wired_defroute_no_gatewaydev_yes); + g_test_add_func(TPATH "routes/read-static", test_read_wired_static_routes); + g_test_add_func(TPATH "routes/read-static-legacy", test_read_wired_static_routes_legacy); + + nmtst_add_test_func(TPATH "wired/read/manual/1", + test_read_wired_ipv4_manual, + TEST_IFCFG_DIR "/ifcfg-test-wired-ipv4-manual-1", + "System test-wired-ipv4-manual-1"); + nmtst_add_test_func(TPATH "wired/read/manual/2", + test_read_wired_ipv4_manual, + TEST_IFCFG_DIR "/ifcfg-test-wired-ipv4-manual-2", + "System test-wired-ipv4-manual-2"); + nmtst_add_test_func(TPATH "wired/read/manual/3", + test_read_wired_ipv4_manual, + TEST_IFCFG_DIR "/ifcfg-test-wired-ipv4-manual-3", + "System test-wired-ipv4-manual-3"); + nmtst_add_test_func(TPATH "wired/read/manual/4", + test_read_wired_ipv4_manual, + TEST_IFCFG_DIR "/ifcfg-test-wired-ipv4-manual-4", + "System test-wired-ipv4-manual-4"); + + g_test_add_func(TPATH "user/1", test_user_1); + + g_test_add_func(TPATH "wired/ipv6-manual", test_read_wired_ipv6_manual); + + nmtst_add_test_func(TPATH "wired-ipv6-only/0", + test_read_wired_ipv6_only, + TEST_IFCFG_DIR "/ifcfg-test-wired-ipv6-only", + "System test-wired-ipv6-only"); + nmtst_add_test_func(TPATH "wired-ipv6-only/1", + test_read_wired_ipv6_only, + TEST_IFCFG_DIR "/ifcfg-test-wired-ipv6-only-1", + "System test-wired-ipv6-only-1"); + + g_test_add_func(TPATH "wired/dhcpv6-only", test_read_wired_dhcp6_only); + g_test_add_func(TPATH "wired/autoip", test_read_wired_autoip); + g_test_add_func(TPATH "wired/onboot/no", test_read_onboot_no); + g_test_add_func(TPATH "wired/no-ip", test_read_noip); + g_test_add_func(TPATH "802-1x/peap/mschapv2", test_read_wired_8021x_peap_mschapv2); + + nmtst_add_test_func(TPATH "test-wired-8021x-tls/agent", + test_read_wired_8021x_tls_secret_flags, + TEST_IFCFG_DIR "/ifcfg-test-wired-8021x-tls-agent", + GINT_TO_POINTER(NM_SETTING_SECRET_FLAG_AGENT_OWNED)); + nmtst_add_test_func( + TPATH "test-wired-8021x-tls/always", + test_read_wired_8021x_tls_secret_flags, + TEST_IFCFG_DIR "/ifcfg-test-wired-8021x-tls-always", + GINT_TO_POINTER(NM_SETTING_SECRET_FLAG_AGENT_OWNED | NM_SETTING_SECRET_FLAG_NOT_SAVED)); + + g_test_add_func(TPATH "802-1x/subj-matches", test_read_write_802_1X_subj_matches); + g_test_add_func(TPATH "802-1x/ttls-eapgtc", test_read_802_1x_ttls_eapgtc); + g_test_add_func(TPATH "802-1x/password_raw", test_read_write_802_1x_password_raw); + g_test_add_func(TPATH "802-1x/tls-p12-no-client-cert", test_read_802_1x_tls_p12_no_client_cert); + + g_test_add_data_func(TPATH "wired/read/aliases/good/0", + GINT_TO_POINTER(0), + test_read_wired_aliases_good); + g_test_add_data_func(TPATH "wired/read/aliases/good/3", + GINT_TO_POINTER(3), + test_read_wired_aliases_good); + g_test_add_func(TPATH "wired/read/aliases/bad1", test_read_wired_aliases_bad_1); + g_test_add_func(TPATH "wired/read/aliases/bad2", test_read_wired_aliases_bad_2); + g_test_add_func(TPATH "wifi/read/open", test_read_wifi_open); + g_test_add_func(TPATH "wifi/read/open/auto", test_read_wifi_open_auto); + g_test_add_func(TPATH "wifi/read/open/hex-ssid", test_read_wifi_open_ssid_hex); + g_test_add_func(TPATH "wifi/read/open-ssid/bad-hex", test_read_wifi_open_ssid_hex_bad); + g_test_add_data_func(TPATH "wifi/read/open-ssid/long-hex", + TEST_IFCFG_WIFI_OPEN_SSID_LONG_HEX, + test_read_wifi_open_ssid_bad); + g_test_add_data_func(TPATH "wifi/read/open-ssid/long-quoted", + TEST_IFCFG_WIFI_OPEN_SSID_LONG_QUOTED, + test_read_wifi_open_ssid_bad); + g_test_add_func(TPATH "wifi/read/open/quoted-ssid", test_read_wifi_open_ssid_quoted); + g_test_add_func(TPATH "wifi/read/wep", test_read_wifi_wep); + g_test_add_func(TPATH "wifi/read/wep/adhoc", test_read_wifi_wep_adhoc); + g_test_add_func(TPATH "wifi/read/wep/passphrase", test_read_wifi_wep_passphrase); + g_test_add_func(TPATH "wifi/read/wep/40-ascii", test_read_wifi_wep_40_ascii); + g_test_add_func(TPATH "wifi/read/wep/104-ascii", test_read_wifi_wep_104_ascii); + g_test_add_func(TPATH "wifi/read/leap", test_read_wifi_leap); + + nmtst_add_test_func(TPATH "wifi-leap-secret-flags/agent", + test_read_wifi_leap_secret_flags, + TEST_IFCFG_DIR "/ifcfg-test-wifi-leap-agent", + GINT_TO_POINTER(NM_SETTING_SECRET_FLAG_AGENT_OWNED)); + nmtst_add_test_func( + TPATH "wifi-leap-secret-flags/ask", + test_read_wifi_leap_secret_flags, + TEST_IFCFG_DIR "/ifcfg-test-wifi-leap-always-ask", + GINT_TO_POINTER(NM_SETTING_SECRET_FLAG_AGENT_OWNED | NM_SETTING_SECRET_FLAG_NOT_SAVED)); + + g_test_add_func(TPATH "wifi/read/wpa-psk", test_read_wifi_wpa_psk); + g_test_add_func(TPATH "wifi/read/wpa-psk/2", test_read_wifi_wpa_psk_2); + g_test_add_func(TPATH "wifi/read/wpa-psk/unquoted", test_read_wifi_wpa_psk_unquoted); + g_test_add_func(TPATH "wifi/read/wpa-psk/unquoted2", test_read_wifi_wpa_psk_unquoted2); + g_test_add_func(TPATH "wifi/read/wpa-psk/adhoc", test_read_wifi_wpa_psk_adhoc); + g_test_add_func(TPATH "wifi/read/wpa-psk/hex", test_read_wifi_wpa_psk_hex); + g_test_add_func(TPATH "wifi/read/sae", test_read_wifi_sae); + g_test_add_func(TPATH "wifi/read/owe", test_read_wifi_owe); + g_test_add_func(TPATH "wifi/read/dynamic-wep/leap", test_read_wifi_dynamic_wep_leap); + g_test_add_func(TPATH "wifi/read/wpa/eap/tls", test_read_wifi_wpa_eap_tls); + g_test_add_func(TPATH "wifi/read/wpa/eap/ttls/tls", test_read_wifi_wpa_eap_ttls_tls); + g_test_add_func(TPATH "wifi/read/wpa/eap-suite-b-192/tls", + test_read_wifi_wpa_eap_suite_b_192_tls); + g_test_add_func(TPATH "wifi/read/dynamic-wep/eap/ttls/chap", test_read_wifi_wep_eap_ttls_chap); + g_test_add_func(TPATH "wifi/read-band-a", test_read_wifi_band_a); + g_test_add_func(TPATH "wifi/read-band-a-channel-mismatch", + test_read_wifi_band_a_channel_mismatch); + g_test_add_func(TPATH "wifi/read-band-bg-channel-mismatch", + test_read_wifi_band_bg_channel_mismatch); + g_test_add_func(TPATH "wifi/read-hidden", test_read_wifi_hidden); + + nmtst_add_test_func(TPATH "wifi/read-mac-random-always", + test_read_wifi_mac_random, + "always", + GINT_TO_POINTER(NM_SETTING_MAC_RANDOMIZATION_ALWAYS)); + nmtst_add_test_func(TPATH "wifi/read-mac-random-never", + test_read_wifi_mac_random, + "never", + GINT_TO_POINTER(NM_SETTING_MAC_RANDOMIZATION_NEVER)); + nmtst_add_test_func(TPATH "wifi/read-mac-random-default", + test_read_wifi_mac_random, + "default", + GINT_TO_POINTER(NM_SETTING_MAC_RANDOMIZATION_DEFAULT)); + nmtst_add_test_func(TPATH "wifi/read-mac-random-missing", + test_read_wifi_mac_random, + "missing", + GINT_TO_POINTER(NM_SETTING_MAC_RANDOMIZATION_DEFAULT)); + + nmtst_add_test_func(TPATH "wifi/write-mac-random-always", + test_write_wifi_mac_random, + "always", + GINT_TO_POINTER(NM_SETTING_MAC_RANDOMIZATION_ALWAYS), + "always"); + nmtst_add_test_func(TPATH "wifi/write-mac-random-never", + test_write_wifi_mac_random, + "never", + GINT_TO_POINTER(NM_SETTING_MAC_RANDOMIZATION_NEVER), + "never"); + nmtst_add_test_func(TPATH "wifi/write-mac-random-default", + test_write_wifi_mac_random, + "default", + GINT_TO_POINTER(NM_SETTING_MAC_RANDOMIZATION_DEFAULT), + "default"); + nmtst_add_test_func(TPATH "wifi/write-mac-random-missing", + test_write_wifi_mac_random, + "missing", + GINT_TO_POINTER(NM_SETTING_MAC_RANDOMIZATION_NEVER), + "never"); + + g_test_add_func(TPATH "wifi/read/wep-no-keys", test_read_wifi_wep_no_keys); + g_test_add_func(TPATH "wifi/read/wep-agent-keys", test_read_wifi_wep_agent_keys); + g_test_add_func(TPATH "infiniband/read", test_read_infiniband); + g_test_add_func(TPATH "vlan/read", test_read_vlan_interface); + g_test_add_func(TPATH "vlan/read-flags-1", test_read_vlan_flags_1); + g_test_add_func(TPATH "vlan/read-flags-2", test_read_vlan_flags_2); + g_test_add_func(TPATH "vlan/read/only-vlanid", test_read_vlan_only_vlan_id); + g_test_add_func(TPATH "vlan/read/only-device", test_read_vlan_only_device); + g_test_add_func(TPATH "vlan/read/physdev", test_read_vlan_physdev); + g_test_add_func(TPATH "vlan/read/reorder-hdr-1", test_read_vlan_reorder_hdr_1); + g_test_add_func(TPATH "vlan/read/reorder-hdr-2", test_read_vlan_reorder_hdr_2); + g_test_add_func(TPATH "wired/read/read-wake-on-lan", test_read_wired_wake_on_lan); + g_test_add_func(TPATH "wired/read/read-auto-negotiate-off", test_read_wired_auto_negotiate_off); + g_test_add_func(TPATH "wired/read/read-auto-negotiate-on", test_read_wired_auto_negotiate_on); + g_test_add_func(TPATH "wired/read/unkwnown-ethtool-opt", test_read_wired_unknown_ethtool_opt); + + g_test_add_func(TPATH "wired/write/static", test_write_wired_static); + g_test_add_func(TPATH "wired/write/static-with-generic", test_write_wired_static_with_generic); + g_test_add_func(TPATH "wired/write/static-ip6-only", test_write_wired_static_ip6_only); + g_test_add_func(TPATH "wired/write-static-routes", test_write_wired_static_routes); + g_test_add_func(TPATH "wired/read-write-static-routes-legacy", + test_read_write_static_routes_legacy); + g_test_add_func(TPATH "wired/write/dhcp", test_write_wired_dhcp); + g_test_add_func(TPATH "wired/write-dhcp-plus-ip", test_write_wired_dhcp_plus_ip); + g_test_add_func(TPATH "wired/write/dhcp-8021x-peap-mschapv2", + test_write_wired_dhcp_8021x_peap_mschapv2); + g_test_add_func(TPATH "wired/write/match", test_write_wired_match); + g_test_add_func(TPATH "wired/write/routing-rules", test_write_routing_rules); + +#define _add_test_write_wired_8021x_tls(testpath, scheme, flags) \ + nmtst_add_test_func(testpath, \ + test_write_wired_8021x_tls, \ + GINT_TO_POINTER(scheme), \ + GINT_TO_POINTER(flags)) + _add_test_write_wired_8021x_tls(TPATH "wired-8021x-tls/1", + NM_SETTING_802_1X_CK_SCHEME_PATH, + NM_SETTING_SECRET_FLAG_AGENT_OWNED); + _add_test_write_wired_8021x_tls(TPATH "wired-8021x-tls/2", + NM_SETTING_802_1X_CK_SCHEME_PATH, + NM_SETTING_SECRET_FLAG_NOT_SAVED); + _add_test_write_wired_8021x_tls(TPATH "wired-8021x-tls/3", + NM_SETTING_802_1X_CK_SCHEME_PATH, + NM_SETTING_SECRET_FLAG_AGENT_OWNED + | NM_SETTING_SECRET_FLAG_NOT_SAVED); + _add_test_write_wired_8021x_tls(TPATH "wired-8021x-tls/4", + NM_SETTING_802_1X_CK_SCHEME_BLOB, + NM_SETTING_SECRET_FLAG_NONE); + + g_test_add_func(TPATH "wired/write-aliases", test_write_wired_aliases); + g_test_add_func(TPATH "ipv4/write-static-addresses-GATEWAY", test_write_gateway); + g_test_add_func(TPATH "wired/write-wake-on-lan", test_write_wired_wake_on_lan); + g_test_add_func(TPATH "wired/write-auto-negotiate-off", test_write_wired_auto_negotiate_off); + g_test_add_func(TPATH "wired/write-auto-negotiate-on", test_write_wired_auto_negotiate_on); + g_test_add_func(TPATH "wifi/write/open", test_write_wifi_open); + g_test_add_func(TPATH "wifi/write/open/hex-ssid", test_write_wifi_open_hex_ssid); + g_test_add_func(TPATH "wifi/write/wep", test_write_wifi_wep); + g_test_add_func(TPATH "wifi/write/wep/adhoc", test_write_wifi_wep_adhoc); + g_test_add_func(TPATH "wifi/write/wep/passphrase", test_write_wifi_wep_passphrase); + g_test_add_func(TPATH "wifi/write/wep/40-ascii", test_write_wifi_wep_40_ascii); + g_test_add_func(TPATH "wifi/write/wep/104-ascii", test_write_wifi_wep_104_ascii); + g_test_add_func(TPATH "wifi/write/leap", test_write_wifi_leap); + g_test_add_data_func(TPATH "wifi/write/leap/flags/agent", + GUINT_TO_POINTER(NM_SETTING_SECRET_FLAG_AGENT_OWNED), + test_write_wifi_leap_secret_flags); + g_test_add_data_func(TPATH "wifi/write/leap/flags/not-saved", + GUINT_TO_POINTER(NM_SETTING_SECRET_FLAG_NOT_SAVED), + test_write_wifi_leap_secret_flags); + g_test_add_data_func( + TPATH "wifi/write/leap/flags/agent-and-not-saved", + GUINT_TO_POINTER(NM_SETTING_SECRET_FLAG_AGENT_OWNED | NM_SETTING_SECRET_FLAG_NOT_SAVED), + test_write_wifi_leap_secret_flags); + +#define _add_test_write_wifi_wpa_psk(testpath, name, wep_group, wpa, wpa2, psk) \ + nmtst_add_test_func(testpath, \ + test_write_wifi_wpa_psk, \ + name, \ + GPOINTER_TO_INT(wep_group), \ + GPOINTER_TO_INT(wpa), \ + GPOINTER_TO_INT(wpa2), \ + psk) + _add_test_write_wifi_wpa_psk(TPATH "wifi-wpa-psk/wpa-psk-write", + "Test Write Wifi WPA PSK", + FALSE, + TRUE, + FALSE, + DEFAULT_HEX_PSK); + _add_test_write_wifi_wpa_psk(TPATH "wifi-wpa-psk/wpa2-psk-write", + "Test Write Wifi WPA2 PSK", + FALSE, + FALSE, + TRUE, + DEFAULT_HEX_PSK); + _add_test_write_wifi_wpa_psk(TPATH "wifi-wpa-psk/wpa-wpa2-psk-write", + "Test Write Wifi WPA WPA2 PSK", + FALSE, + TRUE, + TRUE, + DEFAULT_HEX_PSK); + _add_test_write_wifi_wpa_psk(TPATH "wifi-wpa-psk/wep-wpa-wpa2-psk-write", + "Test Write Wifi WEP WPA WPA2 PSK", + TRUE, + TRUE, + TRUE, + DEFAULT_HEX_PSK); + _add_test_write_wifi_wpa_psk(TPATH "wifi-wpa-psk/wpa-wpa2-psk-passphrase-write", + "Test Write Wifi WPA WPA2 PSK Passphrase", + FALSE, + TRUE, + TRUE, + "really insecure passphrase04!"); + _add_test_write_wifi_wpa_psk(TPATH "wifi-wpa-psk/wpa-wpa2-psk-passphrase-write-spec-chars", + "Test Write Wifi WPA WPA2 PSK Passphrase Special Chars", + FALSE, + TRUE, + TRUE, + "blah`oops\"grr'$*@~!%\\"); + + g_test_add_func(TPATH "wifi/write/wpa/psk/adhoc", test_write_wifi_wpa_psk_adhoc); + g_test_add_func(TPATH "wifi/write/wpa/eap/tls", test_write_wifi_wpa_eap_tls); + g_test_add_func(TPATH "wifi/write/wpa/eap/ttls/tls", test_write_wifi_wpa_eap_ttls_tls); + g_test_add_func(TPATH "wifi/write/wpa/eap/ttls/mschapv2", + test_write_wifi_wpa_eap_ttls_mschapv2); + g_test_add_func(TPATH "wifi/write/dynamic-wep/leap", test_write_wifi_dynamic_wep_leap); + g_test_add_func(TPATH "wifi/write-wpa-then-open", test_write_wifi_wpa_then_open); + g_test_add_func(TPATH "wifi/write-wpa-then-wep-with-perms", + test_write_wifi_wpa_then_wep_with_perms); + g_test_add_func(TPATH "wifi/write-hidden", test_write_wifi_hidden); + g_test_add_func(TPATH "wifi/write-band-a", test_write_wifi_band_a); + g_test_add_func(TPATH "wifi/write-ap-mode", test_write_wifi_ap_mode); + + g_test_add_func(TPATH "s390/read-qeth-static", test_read_wired_qeth_static); + g_test_add_func(TPATH "s390/write-qeth-dhcp", test_write_wired_qeth_dhcp); + g_test_add_func(TPATH "s390/read-ctc-static", test_read_wired_ctc_static); + g_test_add_func(TPATH "s390/write-ctc-dhcp", test_write_wired_ctc_dhcp); + + g_test_add_func(TPATH "permissions/read", test_read_permissions); + g_test_add_func(TPATH "permissions/write", test_write_permissions); + g_test_add_func(TPATH "wifi/write-wep-agent-keys", test_write_wifi_wep_agent_keys); + g_test_add_func(TPATH "infiniband/write", test_write_infiniband); + g_test_add_func(TPATH "vlan/write", test_write_vlan); + g_test_add_func(TPATH "vlan/write-flags", test_write_vlan_flags); + g_test_add_func(TPATH "vlan/write-only-vlanid", test_write_vlan_only_vlanid); + g_test_add_func(TPATH "vlan/write-vlan-reorder-hdr", test_write_vlan_reorder_hdr); + g_test_add_func(TPATH "wired/write-missing-ipv6", test_write_ethernet_missing_ipv6); + g_test_add_func(TPATH "write-dns-options", test_write_dns_options); + + g_test_add_func(TPATH "ibft/ignored", test_read_ibft_ignored); + + g_test_add_func(TPATH "dcb/read-basic", test_read_dcb_basic); + g_test_add_func(TPATH "dcb/write-basic", test_write_dcb_basic); + g_test_add_func(TPATH "dcb/default-app-priorities", test_read_dcb_default_app_priorities); + g_test_add_func(TPATH "dcb/bad-booleans", test_read_dcb_bad_booleans); + g_test_add_func(TPATH "dcb/short-booleans", test_read_dcb_short_booleans); + g_test_add_func(TPATH "dcb/bad-uints", test_read_dcb_bad_uints); + g_test_add_func(TPATH "dcb/short-uints", test_read_dcb_short_uints); + g_test_add_func(TPATH "dcb/bad-percent", test_read_dcb_bad_percent); + g_test_add_func(TPATH "dcb/short-percent", test_read_dcb_short_percent); + g_test_add_func(TPATH "dcb/pgpct-not-100", test_read_dcb_pgpct_not_100); + g_test_add_data_func(TPATH "fcoe/fabric", + (gpointer) NM_SETTING_DCB_FCOE_MODE_FABRIC, + test_read_fcoe_mode); + g_test_add_data_func(TPATH "fcoe/vn2vn", + (gpointer) NM_SETTING_DCB_FCOE_MODE_VN2VN, + test_read_fcoe_mode); + g_test_add_data_func(TPATH "fcoe/write-fabric", + (gpointer) NM_SETTING_DCB_FCOE_MODE_FABRIC, + test_write_fcoe_mode); + g_test_add_data_func(TPATH "fcoe/write-vn2vn", + (gpointer) NM_SETTING_DCB_FCOE_MODE_VN2VN, + test_write_fcoe_mode); + + g_test_add_func(TPATH "bond/read-master", test_read_bond_main); + g_test_add_func(TPATH "bond/read-master-eth-type", test_read_bond_eth_type); + g_test_add_func(TPATH "bond/read-slave", test_read_bond_slave); + g_test_add_func(TPATH "bond/read-slave-ib", test_read_bond_slave_ib); + g_test_add_func(TPATH "bond/write-master", test_write_bond_main); + g_test_add_func(TPATH "bond/write-slave", test_write_bond_slave); + g_test_add_func(TPATH "bond/write-slave-ib", test_write_bond_slave_ib); + g_test_add_func(TPATH "bond/bonding-opts-numeric-mode", test_read_bond_opts_mode_numeric); + + g_test_add_func(TPATH "bridge/read-master", test_read_bridge_main); + g_test_add_func(TPATH "bridge/write-master", test_write_bridge_main); + g_test_add_func(TPATH "bridge/read-component", test_read_bridge_component); + g_test_add_func(TPATH "bridge/write-component", test_write_bridge_component); + g_test_add_func(TPATH "bridge/read-missing-stp", test_read_bridge_missing_stp); + + g_test_add_data_func(TPATH "team/read-master-1", + TEST_IFCFG_DIR "/ifcfg-test-team-master-1", + test_read_team_master); + g_test_add_data_func(TPATH "team/read-master-2", + TEST_IFCFG_DIR "/ifcfg-test-team-master-2", + test_read_team_master); + g_test_add_data_func(TPATH "team/read-master-invalid", + TEST_IFCFG_DIR "/ifcfg-test-team-master-invalid", + test_read_team_master_invalid); + g_test_add_func(TPATH "team/write-master", test_write_team_master); + g_test_add_data_func(TPATH "team/read-port-1", + TEST_IFCFG_DIR "/ifcfg-test-team-port-1", + test_read_team_port); + g_test_add_data_func(TPATH "team/read-port-2", + TEST_IFCFG_DIR "/ifcfg-test-team-port-2", + test_read_team_port); + g_test_add_func(TPATH "team/write-port", test_write_team_port); + g_test_add_func(TPATH "team/write-infiniband-port", test_write_team_infiniband_port); + g_test_add_func(TPATH "team/read-port-empty-config", test_read_team_port_empty_config); + g_test_add_func(TPATH "team/reread-slave", test_team_reread_slave); + + g_test_add_func(TPATH "proxy/read-proxy-basic", test_read_proxy_basic); + g_test_add_func(TPATH "proxy/write-proxy-basic", test_write_proxy_basic); + + g_test_add_func(TPATH "sit/read/ignore", test_sit_read_ignore); + + /* Stuff we expect to fail for now */ + g_test_add_func(TPATH "pppoe/write-wired", test_write_wired_pppoe); + g_test_add_func(TPATH "vpn/write", test_write_vpn); + g_test_add_data_func(TPATH "wwan/write-gsm", + GUINT_TO_POINTER(TRUE), + test_write_mobile_broadband); + g_test_add_data_func(TPATH "wwan/write-cdma", + GUINT_TO_POINTER(FALSE), + test_write_mobile_broadband); + + g_test_add_func(TPATH "no-trailing-newline", test_ifcfg_no_trailing_newline); + + g_test_add_func(TPATH "utils/name", test_utils_name); + g_test_add_func(TPATH "utils/path", test_utils_path); + g_test_add_func(TPATH "utils/ignore", test_utils_ignore); + + g_test_add_func(TPATH "sriov/read", test_sriov_read); + g_test_add_func(TPATH "sriov/write", test_sriov_write); + + g_test_add_func(TPATH "tc/read", test_tc_read); + g_test_add_func(TPATH "tc/write", test_tc_write); + g_test_add_func(TPATH "utils/test_well_known_keys", test_well_known_keys); + g_test_add_func(TPATH "utils/test_utils_has_route_file_new_syntax", + test_utils_has_route_file_new_syntax); + + g_test_add_func(TPATH "utils/test_ethtool_names", test_ethtool_names); + + return g_test_run(); +} |