diff --git a/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIp6AddressGenerationMode.java b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIp6AddressGenerationMode.java new file mode 100644 index 00000000000..ec2ec59e8a4 --- /dev/null +++ b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIp6AddressGenerationMode.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2023 Eurotech and/or its affiliates and others + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Eurotech + *******************************************************************************/ +package org.eclipse.kura.nm; + +import org.eclipse.kura.nm.enums.NMSettingIP6ConfigAddrGenMode; + +public enum KuraIp6AddressGenerationMode { + + EUI64, + STABLE_PRIVACY; + + public static KuraIp6AddressGenerationMode fromString(String status) { + switch (status) { + case "netIPv6AddressGenModeEUI64": + return KuraIp6AddressGenerationMode.EUI64; + case "netIPv6AddressGenModeStablePrivacy": + return KuraIp6AddressGenerationMode.STABLE_PRIVACY; + default: + throw new IllegalArgumentException( + String.format("Unsupported IPv6 address generation mode: \"%s\"", status)); + } + } + + public static NMSettingIP6ConfigAddrGenMode toNMSettingIP6ConfigAddrGenMode( + KuraIp6AddressGenerationMode privacyValue) { + switch (privacyValue) { + case EUI64: + return NMSettingIP6ConfigAddrGenMode.NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64; + case STABLE_PRIVACY: + return NMSettingIP6ConfigAddrGenMode.NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_STABLE_PRIVACY; + default: + throw new IllegalArgumentException( + String.format("Unsupported IPv6 address generation mode: \"%s\"", privacyValue)); + } + } +} diff --git a/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIp6ConfigurationMethod.java b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIp6ConfigurationMethod.java new file mode 100644 index 00000000000..3ad5caf98e1 --- /dev/null +++ b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIp6ConfigurationMethod.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2023 Eurotech and/or its affiliates and others + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Eurotech + *******************************************************************************/ + +package org.eclipse.kura.nm; + +public enum KuraIp6ConfigurationMethod { + + AUTO, + DHCP, + MANUAL; + + public static KuraIp6ConfigurationMethod fromString(String status) { + switch (status) { + case "netIPv6MethodAuto": + return KuraIp6ConfigurationMethod.AUTO; + case "netIPv6MethodDhcp": + return KuraIp6ConfigurationMethod.DHCP; + case "netIPv6MethodManual": + return KuraIp6ConfigurationMethod.MANUAL; + default: + throw new IllegalArgumentException(String.format("Unsupported IPv6 configuration method: \"%s\"", status)); + + } + + } + +} \ No newline at end of file diff --git a/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIp6Privacy.java b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIp6Privacy.java new file mode 100644 index 00000000000..3d90d43b1ef --- /dev/null +++ b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIp6Privacy.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2023 Eurotech and/or its affiliates and others + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Eurotech + *******************************************************************************/ +package org.eclipse.kura.nm; + +import org.eclipse.kura.nm.enums.NMSettingIP6ConfigPrivacy; + +public enum KuraIp6Privacy { + + DISABLED, + ENABLED_PUBLIC_ADD, + ENABLED_TEMP_ADD; + + public static KuraIp6Privacy fromString(String status) { + switch (status) { + case "netIPv6PrivacyDisabled": + return KuraIp6Privacy.DISABLED; + case "netIPv6PrivacyEnabledPubAdd": + return KuraIp6Privacy.ENABLED_PUBLIC_ADD; + case "netIPv6PrivacyEnabledTempAdd": + return KuraIp6Privacy.ENABLED_TEMP_ADD; + default: + throw new IllegalArgumentException(String.format("Unsupported IPv6 privacy value: \"%s\"", status)); + } + } + + public static NMSettingIP6ConfigPrivacy toNMSettingIP6ConfigPrivacy(KuraIp6Privacy privacyValue) { + switch (privacyValue) { + case DISABLED: + return NMSettingIP6ConfigPrivacy.NM_SETTING_IP6_CONFIG_PRIVACY_DISABLED; + case ENABLED_PUBLIC_ADD: + return NMSettingIP6ConfigPrivacy.NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR; + case ENABLED_TEMP_ADD: + return NMSettingIP6ConfigPrivacy.NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR; + default: + throw new IllegalArgumentException(String.format("Unsupported IPv6 privacy value: \"%s\"", privacyValue)); + } + } +} diff --git a/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIpStatus.java b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIpStatus.java index 817974b4424..1d9e629d4ea 100644 --- a/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIpStatus.java +++ b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIpStatus.java @@ -14,6 +14,7 @@ import java.util.Arrays; import java.util.List; +import java.util.Optional; public enum KuraIpStatus { @@ -55,4 +56,34 @@ public static KuraIpStatus fromString(String status) { } + public static Optional fromString(Optional status) { + + if (status.isPresent()) { + switch (status.get()) { + case "netIPv4StatusDisabled": + case "netIPv6StatusDisabled": + return Optional.of(KuraIpStatus.DISABLED); + case "netIPv4StatusUnmanaged": + case "netIPv6StatusUnmanaged": + return Optional.of(KuraIpStatus.UNMANAGED); + case "netIPv4StatusL2Only": + case "netIPv6StatusL2Only": + return Optional.of(KuraIpStatus.L2ONLY); + case "netIPv4StatusEnabledLAN": + case "netIPv6StatusEnabledLAN": + return Optional.of(KuraIpStatus.ENABLEDLAN); + case "netIPv4StatusEnabledWAN": + case "netIPv6StatusEnabledWAN": + return Optional.of(KuraIpStatus.ENABLEDWAN); + default: + return Optional.of(KuraIpStatus.UNKNOWN); + + } + + } else { + return Optional.empty(); + } + + } + } diff --git a/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/NMDbusConnector.java b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/NMDbusConnector.java index 55483295228..95602d5fb18 100644 --- a/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/NMDbusConnector.java +++ b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/NMDbusConnector.java @@ -372,8 +372,17 @@ private synchronized void manageConfiguredInterface(Device device, String device KuraIpStatus ip4Status = KuraIpStatus .fromString(properties.get(String.class, "net.interface.%s.config.ip4.status", deviceId)); - // Temporary solution while we wait to add complete IPv6 support - KuraIpStatus ip6Status = ip4Status == KuraIpStatus.UNMANAGED ? KuraIpStatus.UNMANAGED : KuraIpStatus.DISABLED; + + Optional ip6OptStatus = KuraIpStatus + .fromString(properties.getOpt(String.class, "net.interface.%s.config.ip6.status", deviceId)); + KuraIpStatus ip6Status; + + if (!ip6OptStatus.isPresent()) { + ip6Status = ip4Status == KuraIpStatus.UNMANAGED ? KuraIpStatus.UNMANAGED : KuraIpStatus.DISABLED; + } else { + ip6Status = ip6OptStatus.get(); + } + KuraInterfaceStatus interfaceStatus = KuraInterfaceStatus.fromKuraIpStatus(ip4Status, ip6Status); if (!CONFIGURATION_SUPPORTED_DEVICE_TYPES.contains(deviceType) diff --git a/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/configuration/NMSettingsConverter.java b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/configuration/NMSettingsConverter.java index a696790123b..8c8beefd1b1 100644 --- a/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/configuration/NMSettingsConverter.java +++ b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/configuration/NMSettingsConverter.java @@ -23,7 +23,10 @@ import java.util.Optional; import org.eclipse.kura.configuration.Password; +import org.eclipse.kura.nm.KuraIp6AddressGenerationMode; +import org.eclipse.kura.nm.KuraIp6Privacy; import org.eclipse.kura.nm.KuraIpStatus; +import org.eclipse.kura.nm.KuraIp6ConfigurationMethod; import org.eclipse.kura.nm.KuraWifiSecurityType; import org.eclipse.kura.nm.NetworkProperties; import org.eclipse.kura.nm.enums.NMDeviceType; @@ -40,6 +43,8 @@ public class NMSettingsConverter { private static final String NM_SETTINGS_CONNECTION = "connection"; private static final String NM_SETTINGS_IPV4_METHOD = "method"; private static final String NM_SETTINGS_IPV6_METHOD = "method"; + private static final String NM_SETTINGS_IPV4_IGNORE_AUTO_DNS = "ignore-auto-dns"; + private static final String NM_SETTINGS_IPV6_IGNORE_AUTO_DNS = "ignore-auto-dns"; private static final String PPP_REFUSE_EAP = "refuse-eap"; private static final String PPP_REFUSE_CHAP = "refuse-chap"; @@ -132,14 +137,14 @@ public static Map> buildIpv4Settings(NetworkProperties props, } if (ip4Status.equals(KuraIpStatus.ENABLEDLAN)) { - settings.put("ignore-auto-dns", new Variant<>(true)); + settings.put(NM_SETTINGS_IPV4_IGNORE_AUTO_DNS, new Variant<>(true)); settings.put("ignore-auto-routes", new Variant<>(true)); } else if (ip4Status.equals(KuraIpStatus.ENABLEDWAN)) { Optional> dnsServers = props.getOptStringList("net.interface.%s.config.ip4.dnsServers", deviceId); if (dnsServers.isPresent()) { settings.put("dns", new Variant<>(convertIp4(dnsServers.get()), "au")); - settings.put("ignore-auto-dns", new Variant<>(true)); + settings.put(NM_SETTINGS_IPV4_IGNORE_AUTO_DNS, new Variant<>(true)); } Optional wanPriority = props.getOpt(Integer.class, "net.interface.%s.config.ip4.wan.priority", @@ -156,10 +161,100 @@ public static Map> buildIpv4Settings(NetworkProperties props, } public static Map> buildIpv6Settings(NetworkProperties props, String deviceId) { + + // buildIpv6Settings doesn't support Unmanaged status. Therefore if ip6.status property is not set, it assumes + // it is disabled. + + Optional ip6OptStatus = KuraIpStatus + .fromString(props.getOpt(String.class, "net.interface.%s.config.ip6.status", deviceId)); + + KuraIpStatus ip6Status = ip6OptStatus.isPresent() ? ip6OptStatus.get() : KuraIpStatus.DISABLED; + + if (ip6Status == KuraIpStatus.UNMANAGED || ip6Status == KuraIpStatus.UNKNOWN) { + throw new IllegalArgumentException("IPv6 status is not supported: " + ip6Status + + ". Build settings should be called only for managed interfaces."); + } + Map> settings = new HashMap<>(); - // Disabled for now - settings.put(NM_SETTINGS_IPV6_METHOD, new Variant<>("disabled")); + if (ip6Status == KuraIpStatus.DISABLED) { + settings.put(NM_SETTINGS_IPV6_METHOD, new Variant<>("disabled")); + return settings; + } + + KuraIp6ConfigurationMethod ip6ConfigMethod = KuraIp6ConfigurationMethod + .fromString(props.get(String.class, "net.interface.%s.config.ip6.address.method", deviceId)); + + if (ip6ConfigMethod.equals(KuraIp6ConfigurationMethod.AUTO)) { + + settings.put(NM_SETTINGS_IPV6_METHOD, new Variant<>("auto")); + + Optional addressGenerationMode = props.getOpt(String.class, + "net.interface.%s.config.ip6.addr.gen.mode", deviceId); + + addressGenerationMode.ifPresent(value -> { + KuraIp6AddressGenerationMode ipv6AddressGenerationMode = KuraIp6AddressGenerationMode + .fromString(addressGenerationMode.get()); + settings.put("addr-gen-mode", new Variant<>(KuraIp6AddressGenerationMode + .toNMSettingIP6ConfigAddrGenMode(ipv6AddressGenerationMode).toInt32())); + }); + + Optional privacy = props.getOpt(String.class, "net.interface.%s.config.ip6.privacy", deviceId); + privacy.ifPresent(value -> { + KuraIp6Privacy ip6Privacy = KuraIp6Privacy.fromString(privacy.get()); + settings.put("ip6-privacy", + new Variant<>(KuraIp6Privacy.toNMSettingIP6ConfigPrivacy(ip6Privacy).toInt32())); + }); + + } else if (ip6ConfigMethod.equals(KuraIp6ConfigurationMethod.DHCP)) { + + settings.put(NM_SETTINGS_IPV6_METHOD, new Variant<>("dhcp")); + + } else if (ip6ConfigMethod.equals(KuraIp6ConfigurationMethod.MANUAL)) { + + settings.put(NM_SETTINGS_IPV6_METHOD, new Variant<>("manual")); + + String address = props.get(String.class, "net.interface.%s.config.ip6.address", deviceId); + Short prefix = props.get(Short.class, "net.interface.%s.config.ip6.prefix", deviceId); + + Map> addressEntry = new HashMap<>(); + addressEntry.put("address", new Variant<>(address)); + addressEntry.put("prefix", new Variant<>(new UInt32(prefix))); + + if (ip6Status.equals(KuraIpStatus.ENABLEDWAN)) { + Optional gateway = props.getOpt(String.class, "net.interface.%s.config.ip6.gateway", deviceId); + gateway.ifPresent(gatewayAddress -> settings.put("gateway", new Variant<>(gatewayAddress))); + } + + List>> addressData = Arrays.asList(addressEntry); + settings.put("address-data", new Variant<>(addressData, "aa{sv}")); + + } else { + throw new IllegalArgumentException( + String.format("Unsupported IPv6 address generation mode: \"%s\"", ip6ConfigMethod)); + } + + if (ip6Status.equals(KuraIpStatus.ENABLEDLAN)) { + settings.put(NM_SETTINGS_IPV6_IGNORE_AUTO_DNS, new Variant<>(true)); + settings.put("ignore-auto-routes", new Variant<>(true)); + + } else if (ip6Status.equals(KuraIpStatus.ENABLEDWAN)) { + Optional> dnsServers = props.getOptStringList("net.interface.%s.config.ip6.dnsServers", + deviceId); + + dnsServers.ifPresent(value -> { + settings.put("dns", new Variant<>(convertIp6(value), "aay")); + settings.put(NM_SETTINGS_IPV6_IGNORE_AUTO_DNS, new Variant<>(true)); + }); + + Optional wanPriority = props.getOpt(Integer.class, "net.interface.%s.config.ip6.wan.priority", + deviceId); + + wanPriority.ifPresent(value -> settings.put("route-metric", new Variant<>(value.longValue()))); + + } else { + logger.warn("Unexpected ip status received: \"{}\". Ignoring", ip6Status); + } return settings; } @@ -375,6 +470,31 @@ private static UInt32 convertIp4(String ipAddrString) throws UnknownHostExceptio return new UInt32(result); } + private static List> convertIp6(List ipAddrList) { + List> uint32Addresses = new ArrayList<>(); + for (String address : ipAddrList) { + try { + uint32Addresses.add(convertIp6(address)); + } catch (UnknownHostException e) { + logger.warn("Cannot convert ip address \"{}\" because: ", address, e); + } + } + return uint32Addresses; + } + + private static List convertIp6(String ipAddrString) throws UnknownHostException { + InetAddress address = InetAddress.getByName(ipAddrString); + + byte[] dnsByteArray = address.getAddress(); + + List dnsAddress = new ArrayList<>(); + for (int i = 0; i < dnsByteArray.length; i++) { + dnsAddress.add(dnsByteArray[i]); + } + + return dnsAddress; + } + private static String wifiModeConvert(String kuraMode) { switch (kuraMode) { case "INFRA": diff --git a/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/enums/NMSettingIP6ConfigAddrGenMode.java b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/enums/NMSettingIP6ConfigAddrGenMode.java new file mode 100644 index 00000000000..5c3cb32be0d --- /dev/null +++ b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/enums/NMSettingIP6ConfigAddrGenMode.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2023 Eurotech and/or its affiliates and others + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Eurotech + *******************************************************************************/ +package org.eclipse.kura.nm.enums; + +public enum NMSettingIP6ConfigAddrGenMode { + + NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64(0), + NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_STABLE_PRIVACY(1), + NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_DEFAULT_OR_EUI64(2), + NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_DEFAULT(3); + + private int value; + + private NMSettingIP6ConfigAddrGenMode(int value) { + this.value = value; + } + + public Integer toInt32() { + return this.value; + } + + public static NMSettingIP6ConfigAddrGenMode fromInt32(Integer intValue) { + switch (intValue) { + case 0: + return NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_EUI64; + case 1: + return NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_STABLE_PRIVACY; + case 2: + return NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_DEFAULT_OR_EUI64; + case 3: + return NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_DEFAULT; + default: + return NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_DEFAULT; + } + } + +} diff --git a/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/enums/NMSettingIP6ConfigPrivacy.java b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/enums/NMSettingIP6ConfigPrivacy.java new file mode 100644 index 00000000000..e083202204e --- /dev/null +++ b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/enums/NMSettingIP6ConfigPrivacy.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2023 Eurotech and/or its affiliates and others + * + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Eurotech + *******************************************************************************/ +package org.eclipse.kura.nm.enums; + +public enum NMSettingIP6ConfigPrivacy { + + NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN(-1), + NM_SETTING_IP6_CONFIG_PRIVACY_DISABLED(0), + NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR(1), + NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR(2); + + private int value; + + private NMSettingIP6ConfigPrivacy(int value) { + this.value = value; + } + + public Integer toInt32() { + return this.value; + } + + public static NMSettingIP6ConfigPrivacy fromInt32(Integer intValue) { + switch (intValue) { + case -1: + return NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN; + case 0: + return NM_SETTING_IP6_CONFIG_PRIVACY_DISABLED; + case 1: + return NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR; + case 2: + return NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR; + default: + return NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN; + } + } + +} diff --git a/kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/configuration/NMSettingsConverterTest.java b/kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/configuration/NMSettingsConverterTest.java index 4da3d3a89db..4dc13d3618f 100644 --- a/kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/configuration/NMSettingsConverterTest.java +++ b/kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/configuration/NMSettingsConverterTest.java @@ -51,6 +51,9 @@ public class NMSettingsConverterTest { Boolean hasAnIllegalArgumentExceptionThrown = false; Boolean hasAGenericExecptionBeenThrown = false; + private static final List IP6_BYTE_ARRAY_ADDRESS = Arrays + .asList(new Byte[] { 32, 1, 72, 96, 72, 96, 0, 0, 0, 0, 0, 0, 0, 0, -120, 68 }); + @Test public void buildSettingsShouldThrowWhenGivenEmptyMap() { givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); @@ -220,6 +223,229 @@ public void buildIpv4SettingsShouldNotPopulateWanPriorityPropertyIfNotWAN() { thenResultingMapNotContains("route-metric"); } + @Test + public void buildIpv6SettingsShouldThrowWhitWrongMethod() { + givenMapWith("net.interface.wlan0.config.ip6.address.method", "WrongMethod"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledWAN"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildIpv6SettingsIsRunWith(this.networkProperties, "wlan0"); + + thenIllegalArgumentExceptionThrown(); + } + + @Test + public void buildIpv6SettingsShouldNotSetIgnoreAutoDNSWhenGivenExpectedMapWithAutoEnableAndWAN() { + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodAuto"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledWAN"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildIpv6SettingsIsRunWith(this.networkProperties, "wlan0"); + + thenNoExceptionsHaveBeenThrown(); + thenResultingMapContains("method", "auto"); + thenResultingMapNotContains("ignore-auto-dns"); + } + + @Test + public void buildIpv6SettingsShouldSetWhenGivenExpectedMapWithAutoEnableAndWAN() { + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodAuto"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledWAN"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildIpv6SettingsIsRunWith(this.networkProperties, "wlan0"); + + thenNoExceptionsHaveBeenThrown(); + thenResultingMapContains("method", "auto"); + } + + @Test + public void buildIpv6SettingsShouldWorkWhenGivenExpectedMapWithDhcpEnableAndWAN() { + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodDhcp"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledWAN"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildIpv6SettingsIsRunWith(this.networkProperties, "wlan0"); + + thenNoExceptionsHaveBeenThrown(); + thenResultingMapContains("method", "dhcp"); + } + + @Test + public void buildIpv6SettingsShouldWorkWhenGivenExpectedMapWithManualEnableAndEnabledForWan() { + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodManual"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledWAN"); + givenMapWith("net.interface.wlan0.config.ip6.address", "fe80::eed:f0a1:d03a:1028"); + givenMapWith("net.interface.wlan0.config.ip6.prefix", (short) 25); + givenMapWith("net.interface.wlan0.config.ip6.dnsServers", "2001:4860:4860:0:0:0:0:8844"); + givenMapWith("net.interface.wlan0.config.ip6.gateway", "fe80::eed:f0a1:d03a:1"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildIpv6SettingsIsRunWith(this.networkProperties, "wlan0"); + + thenNoExceptionsHaveBeenThrown(); + thenResultingMapContains("method", "manual"); + thenResultingMapContains("address-data", buildAddressDataWith("fe80::eed:f0a1:d03a:1028", new UInt32(25))); + thenResultingMapContains("dns", Arrays.asList(IP6_BYTE_ARRAY_ADDRESS)); + thenResultingMapContains("ignore-auto-dns", true); + thenResultingMapContains("gateway", "fe80::eed:f0a1:d03a:1"); + + } + + @Test + public void buildIpv6SettingsShouldWorkWhenGivenExpectedMapWithAutoEnableAndEnabledForLan() { + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodAuto"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledLAN"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildIpv6SettingsIsRunWith(this.networkProperties, "wlan0"); + + thenNoExceptionsHaveBeenThrown(); + thenResultingMapContains("method", "auto"); + thenResultingMapContains("ignore-auto-dns", true); + thenResultingMapContains("ignore-auto-routes", true); + } + + @Test + public void buildIpv6SettingsShouldWorkWhenGivenExpectedMapWithManualEnableAndEnabledForLan() { + + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodManual"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledLAN"); + givenMapWith("net.interface.wlan0.config.ip6.address", "fe80::eed:f0a1:d03a:1028"); + givenMapWith("net.interface.wlan0.config.ip6.prefix", (short) 25); + givenMapWith("net.interface.wlan0.config.ip6.dnsServers", "2001:4860:4860:0:0:0:0:8844"); + givenMapWith("net.interface.wlan0.config.ip6.gateway", "fe80::eed:f0a1:d03a:1"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildIpv6SettingsIsRunWith(this.networkProperties, "wlan0"); + + thenNoExceptionsHaveBeenThrown(); + thenResultingMapContains("method", "manual"); + thenResultingMapContains("address-data", buildAddressDataWith("fe80::eed:f0a1:d03a:1028", new UInt32(25))); + thenResultingMapContains("ignore-auto-dns", true); + thenResultingMapContains("ignore-auto-routes", true); + } + + @Test + public void buildIpv6SettingsShouldWorkWhenGivenExpectedMapWithAutoEnableAndWANEUI64Disabled() { + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodAuto"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledWAN"); + givenMapWith("net.interface.wlan0.config.ip6.addr.gen.mode", "netIPv6AddressGenModeEUI64"); + givenMapWith("net.interface.wlan0.config.ip6.privacy", "netIPv6PrivacyDisabled"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildIpv6SettingsIsRunWith(this.networkProperties, "wlan0"); + + thenNoExceptionsHaveBeenThrown(); + thenResultingMapContains("method", "auto"); + thenResultingMapContains("addr-gen-mode", 0); + thenResultingMapContains("ip6-privacy", 0); + } + + @Test + public void buildIpv6SettingsShouldWorkWhenGivenExpectedMapWithAutoEnableAndWANStablePrivacyPreferPublicAddress() { + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodAuto"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledWAN"); + givenMapWith("net.interface.wlan0.config.ip6.addr.gen.mode", "netIPv6AddressGenModeStablePrivacy"); + givenMapWith("net.interface.wlan0.config.ip6.privacy", "netIPv6PrivacyEnabledPubAdd"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildIpv6SettingsIsRunWith(this.networkProperties, "wlan0"); + + thenNoExceptionsHaveBeenThrown(); + thenResultingMapContains("method", "auto"); + thenResultingMapContains("addr-gen-mode", 1); + thenResultingMapContains("ip6-privacy", 1); + } + + @Test + public void buildIpv6SettingsShouldWorkWhenGivenExpectedMapWithAutoEnableAndWANStablePrivacyPreferTempAddress() { + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodAuto"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledWAN"); + givenMapWith("net.interface.wlan0.config.ip6.addr.gen.mode", "netIPv6AddressGenModeStablePrivacy"); + givenMapWith("net.interface.wlan0.config.ip6.privacy", "netIPv6PrivacyEnabledTempAdd"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildIpv6SettingsIsRunWith(this.networkProperties, "wlan0"); + + thenNoExceptionsHaveBeenThrown(); + thenResultingMapContains("method", "auto"); + thenResultingMapContains("addr-gen-mode", 1); + thenResultingMapContains("ip6-privacy", 2); + } + + @Test + public void buildIpv6SettingsShouldWorkWhenGivenExpectedMapWithDisabled() { + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodAuto"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusDisabled"); + givenMapWith("net.interface.wlan0.config.ip6.addr.gen.mode", "netIPv6AddressGenModeStablePrivacy"); + givenMapWith("net.interface.wlan0.config.ip6.privacy", "netIPv6PrivacyEnabledTempAdd"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildIpv6SettingsIsRunWith(this.networkProperties, "wlan0"); + + thenNoExceptionsHaveBeenThrown(); + thenResultingMapContains("method", "disabled"); + thenResultingMapNotContains("addr-gen-mode"); + thenResultingMapNotContains("ip6-privacy"); + } + + @Test + public void buildIpv6SettingsShouldThrowWhenGivenExpectedMapWithWrongAddressGenMode() { + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodAuto"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledWAN"); + givenMapWith("net.interface.wlan0.config.ip6.addr.gen.mode", "WrongGenAddress"); + givenMapWith("net.interface.wlan0.config.ip6.privacy", "netIPv6PrivacyEnabledTempAdd"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildIpv6SettingsIsRunWith(this.networkProperties, "wlan0"); + + thenIllegalArgumentExceptionThrown(); + } + + @Test + public void buildIpv6SettingsShouldThrowWhenGivenExpectedMapWithWrongPrivacy() { + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodAuto"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledWAN"); + givenMapWith("net.interface.wlan0.config.ip6.addr.gen.mode", "netIPv6AddressGenModeStablePrivacy"); + givenMapWith("net.interface.wlan0.config.ip6.privacy", "WrongPrivacy"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildIpv6SettingsIsRunWith(this.networkProperties, "wlan0"); + + thenIllegalArgumentExceptionThrown(); + } + + @Test + public void buildIpv6SettingsShouldThrowIllegalArgumentExceptionWhenGivenExpectedMapWithManualEnableAndUnmanaged() { + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodManual"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusUnmanaged"); + givenMapWith("net.interface.wlan0.config.ip6.address", "fe80::eed:f0a1:d03a:1028"); + givenMapWith("net.interface.wlan0.config.ip6.prefix", (short) 25); + givenMapWith("net.interface.wlan0.config.ip6.dnsServers", "2001:4860:4860:0:0:0:0:8844"); + givenMapWith("net.interface.wlan0.config.ip6.gateway", "fe80::eed:f0a1:d03a:1"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildIpv6SettingsIsRunWith(this.networkProperties, "wlan0"); + + thenIllegalArgumentExceptionThrown(); + } + + @Test + public void buildIpv6SettingsShouldThrowIllegalArgumentExceptionWhenGivenExpectedMapWithManualEnableAndUnknown() { + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodManual"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusUnknown"); + givenMapWith("net.interface.wlan0.config.ip6.address", "fe80::eed:f0a1:d03a:1028"); + givenMapWith("net.interface.wlan0.config.ip6.prefix", (short) 25); + givenMapWith("net.interface.wlan0.config.ip6.dnsServers", "2001:4860:4860:0:0:0:0:8844"); + givenMapWith("net.interface.wlan0.config.ip6.gateway", "fe80::eed:f0a1:d03a:1"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildIpv6SettingsIsRunWith(this.networkProperties, "wlan0"); + + thenIllegalArgumentExceptionThrown(); + } + @Test public void build80211WirelessSettingsShouldWorkWhenGivenExpectedMapAndSetToInfraAndWithChannelField() { @@ -756,7 +982,7 @@ public void buildConnectionSettingsShouldWorkWithWifiMockedConnection() { } @Test - public void buildSettingsShouldThrowWithStatusUnmanaged() { + public void buildSettingsShouldThrowWithStatusUnmanagedIp4() { givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusUnmanaged"); givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); @@ -767,7 +993,7 @@ public void buildSettingsShouldThrowWithStatusUnmanaged() { } @Test - public void buildSettingsShouldThrowWithStatusUnknown() { + public void buildSettingsShouldThrowWithStatusUnknownIp4() { givenMapWith("net.interface.wlan0.config.ip4.status", "myAwesomeUnknownString"); givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); @@ -778,7 +1004,7 @@ public void buildSettingsShouldThrowWithStatusUnknown() { } @Test - public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiLan() { + public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiLanIp4() { givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusEnabledLAN"); givenMapWith("net.interface.wlan0.config.ip4.address", "192.168.0.12"); @@ -822,7 +1048,7 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiLan() { } @Test - public void buildSettingsShouldWorkWithExpectedConfiguredForInputsWiFiWan() { + public void buildSettingsShouldWorkWithExpectedConfiguredForInputsWiFiWanIp4() { givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusEnabledWAN"); givenMapWith("net.interface.wlan0.config.ip4.address", "192.168.0.12"); @@ -867,7 +1093,7 @@ public void buildSettingsShouldWorkWithExpectedConfiguredForInputsWiFiWan() { } @Test - public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiLanAndHiddenSsid() { + public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiLanAndHiddenSsidIp4() { givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusEnabledLAN"); givenMapWith("net.interface.wlan0.config.ip4.address", "192.168.0.12"); @@ -912,7 +1138,7 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiLanAndHidd } @Test - public void buildSettingsShouldNotSet80211WirelessSecuritySettingsIfSecurityTypeIsSetToNone() { + public void buildSettingsShouldNotSet80211WirelessSecuritySettingsIfSecurityTypeIsSetToNoneIp4() { givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusEnabledLAN"); givenMapWith("net.interface.wlan0.config.ip4.address", "192.168.0.12"); @@ -950,7 +1176,7 @@ public void buildSettingsShouldNotSet80211WirelessSecuritySettingsIfSecurityType } @Test - public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiWanAndHiddenSsid() { + public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiWanAndHiddenSsidIp4() { givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusEnabledWAN"); givenMapWith("net.interface.wlan0.config.ip4.address", "192.168.0.12"); @@ -998,7 +1224,7 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiWanAndHidd } @Test - public void buildSettingsShouldWorkWithExpectedInputsConfiguredForEthernetAndUnmanaged() { + public void buildSettingsShouldWorkWithExpectedInputsConfiguredForEthernetAndUnmanagedIp4() { givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusUnmanaged"); givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); @@ -1009,7 +1235,7 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForEthernetAndUnm } @Test - public void buildSettingsShouldWorkWithExpectedInputsConfiguredForEthernetAndLan() { + public void buildSettingsShouldWorkWithExpectedInputsConfiguredForEthernetAndLanIp4() { givenMapWith("net.interface.eth0.config.dhcpClient4.enabled", false); givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusEnabledLAN"); givenMapWith("net.interface.eth0.config.ip4.address", "192.168.0.12"); @@ -1033,7 +1259,7 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForEthernetAndLan } @Test - public void buildSettingsShouldWorkWithExpectedInputsEthernetAndWan() { + public void buildSettingsShouldWorkWithExpectedInputsEthernetAndWanIp4() { givenMapWith("net.interface.eth0.config.dhcpClient4.enabled", false); givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusEnabledWAN"); givenMapWith("net.interface.eth0.config.ip4.address", "192.168.0.12"); @@ -1060,7 +1286,7 @@ public void buildSettingsShouldWorkWithExpectedInputsEthernetAndWan() { } @Test - public void buildSettingsShouldWorkWithModemSettings() { + public void buildSettingsShouldWorkWithModemSettingsIp4() { givenMapWith("net.interface.1-1.1.config.dhcpClient4.enabled", true); givenMapWith("net.interface.1-1.1.config.ip4.status", "netIPv4StatusEnabledWAN"); givenMapWith("net.interface.1-1.1.config.apn", "mobile.test.com"); @@ -1080,8 +1306,7 @@ public void buildSettingsShouldWorkWithModemSettings() { } @Test - public void buildSettingsShouldThrowDhcpDisabledAndNullIp() { - givenMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusDisabled"); + public void buildSettingsShouldThrowDhcpDisabledAndNullIpIp4() { givenMapWith("net.interface.eth0.config.dhcpClient4.enabled", false); givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusEnabledWAN"); givenMapWith("net.interface.eth0.config.ip4.address", null); @@ -1097,8 +1322,7 @@ public void buildSettingsShouldThrowDhcpDisabledAndNullIp() { } @Test - public void buildSettingsShouldThrowDhcpDisabledAndNullPrefix() { - givenMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusDisabled"); + public void buildSettingsShouldThrowDhcpDisabledAndNullPrefixIp4() { givenMapWith("net.interface.eth0.config.dhcpClient4.enabled", false); givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusEnabledWAN"); givenMapWith("net.interface.eth0.config.ip4.address", "192.168.0.12"); @@ -1114,8 +1338,7 @@ public void buildSettingsShouldThrowDhcpDisabledAndNullPrefix() { } @Test - public void buildSettingsShouldThrowDhcpDisabledAndNullStatus() { - givenMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusDisabled"); + public void buildSettingsShouldThrowDhcpDisabledAndNullStatusIp4() { givenMapWith("net.interface.eth0.config.dhcpClient4.enabled", false); givenMapWith("net.interface.eth0.config.ip4.status", null); givenMapWith("net.interface.eth0.config.ip4.address", "192.168.0.12"); @@ -1131,8 +1354,7 @@ public void buildSettingsShouldThrowDhcpDisabledAndNullStatus() { } @Test - public void buildSettingsShouldThrowDhcpDisabledAndNullWifiSsid() { - givenMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusDisabled"); + public void buildSettingsShouldThrowDhcpDisabledAndNullWifiSsidIp4() { givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusEnabledWAN"); givenMapWith("net.interface.wlan0.config.ip4.address", "192.168.0.12"); @@ -1158,8 +1380,7 @@ public void buildSettingsShouldThrowDhcpDisabledAndNullWifiSsid() { } @Test - public void buildSettingsShouldThrowDhcpDisabledAndNullWifiPassword() { - givenMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusDisabled"); + public void buildSettingsShouldThrowDhcpDisabledAndNullWifiPasswordIp4() { givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusEnabledWAN"); givenMapWith("net.interface.wlan0.config.ip4.address", "192.168.0.12"); @@ -1185,8 +1406,7 @@ public void buildSettingsShouldThrowDhcpDisabledAndNullWifiPassword() { } @Test - public void buildSettingsShouldThrowDhcpDisabledAndNullWifiSecurityType() { - givenMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusDisabled"); + public void buildSettingsShouldThrowDhcpDisabledAndNullWifiSecurityTypeIp4() { givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusEnabledWAN"); givenMapWith("net.interface.wlan0.config.ip4.address", "192.168.0.12"); @@ -1210,6 +1430,1084 @@ public void buildSettingsShouldThrowDhcpDisabledAndNullWifiSecurityType() { thenNoSuchElementExceptionThrown(); } + + @Test + public void buildSettingsShouldThrowWithStatusUnmanagedIp6() { + givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusDisabled"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusUnmanaged"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "wlan0", "wlan0", + NMDeviceType.NM_DEVICE_TYPE_WIFI); + + thenIllegalArgumentExceptionThrown(); + } + + @Test + public void buildSettingsShouldThrowWithStatusUnknownIp6() { + givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusDisabled"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusUnknown"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "wlan0", "wlan0", + NMDeviceType.NM_DEVICE_TYPE_WIFI); + + thenIllegalArgumentExceptionThrown(); + } + + @Test + public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiUnmangedIp6() { + givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusDisabled"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusUnmanaged"); + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodManual"); + givenMapWith("net.interface.wlan0.config.ip6.address", "fe80::eed:f0a1:d03a:1028"); + givenMapWith("net.interface.wlan0.config.ip6.prefix", (short) 25); + givenMapWith("net.interface.wlan0.config.ip6.dnsServers", "2001:4860:4860:0:0:0:0:8844"); + givenMapWith("net.interface.wlan0.config.ip6.gateway", "fe80::eed:f0a1:d03a:1"); + givenMapWith("net.interface.wlan0.config.wifi.mode", "INFRA"); + givenMapWith("net.interface.wlan0.config.wifi.infra.ssid", "ssidtest"); + givenMapWith("net.interface.wlan0.config.wifi.infra.radioMode", "RADIO_MODE_80211a"); + givenMapWith("net.interface.wlan0.config.wifi.infra.channel", "10"); + givenMapWith("net.interface.wlan0.config.wifi.mode", "INFRA"); + givenMapWith("net.interface.wlan0.config.wifi.infra.passphrase", new Password("test")); + givenMapWith("net.interface.wlan0.config.wifi.infra.securityType", "SECURITY_WPA_WPA2"); + givenMapWith("net.interface.wlan0.config.wifi.infra.groupCiphers", "CCMP"); + givenMapWith("net.interface.wlan0.config.wifi.infra.pairwiseCiphers", "CCMP"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "wlan0", "wlan0", + NMDeviceType.NM_DEVICE_TYPE_WIFI); + + thenIllegalArgumentExceptionThrown(); + } + + @Test + public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiLanIp6() { + givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusDisabled"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledLAN"); + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodManual"); + givenMapWith("net.interface.wlan0.config.ip6.address", "fe80::eed:f0a1:d03a:1028"); + givenMapWith("net.interface.wlan0.config.ip6.prefix", (short) 25); + givenMapWith("net.interface.wlan0.config.ip6.dnsServers", "2001:4860:4860:0:0:0:0:8844"); + givenMapWith("net.interface.wlan0.config.ip6.gateway", "fe80::eed:f0a1:d03a:1"); + givenMapWith("net.interface.wlan0.config.wifi.mode", "INFRA"); + givenMapWith("net.interface.wlan0.config.wifi.infra.ssid", "ssidtest"); + givenMapWith("net.interface.wlan0.config.wifi.infra.radioMode", "RADIO_MODE_80211a"); + givenMapWith("net.interface.wlan0.config.wifi.infra.channel", "10"); + givenMapWith("net.interface.wlan0.config.wifi.mode", "INFRA"); + givenMapWith("net.interface.wlan0.config.wifi.infra.passphrase", new Password("test")); + givenMapWith("net.interface.wlan0.config.wifi.infra.securityType", "SECURITY_WPA_WPA2"); + givenMapWith("net.interface.wlan0.config.wifi.infra.groupCiphers", "CCMP"); + givenMapWith("net.interface.wlan0.config.wifi.infra.pairwiseCiphers", "CCMP"); + + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "wlan0", "wlan0", + NMDeviceType.NM_DEVICE_TYPE_WIFI); + + thenNoExceptionsHaveBeenThrown(); + thenResultingBuildAllMapContains("ipv4", "method", "disabled"); + thenResultingBuildAllMapContains("ipv6", "method", "manual"); + thenResultingBuildAllMapContains("ipv6", "address-data", + buildAddressDataWith("fe80::eed:f0a1:d03a:1028", new UInt32(25))); + thenResultingBuildAllMapContains("connection", "id", "kura-wlan0-connection"); + thenResultingBuildAllMapContains("connection", "interface-name", "wlan0"); + thenResultingBuildAllMapContains("connection", "type", "802-11-wireless"); + thenResultingBuildAllMapContains("802-11-wireless", "mode", "infrastructure"); + thenResultingBuildAllMapContainsBytes("802-11-wireless", "ssid", "ssidtest"); + thenResultingBuildAllMapContains("802-11-wireless", "band", "a"); + thenResultingBuildAllMapContains("802-11-wireless", "channel", new UInt32(Short.parseShort("10"))); + thenResultingBuildAllMapContains("802-11-wireless-security", "psk", new Password("test").toString()); + thenResultingBuildAllMapContains("802-11-wireless-security", "key-mgmt", "wpa-psk"); + thenResultingBuildAllMapContains("802-11-wireless-security", "group", + new Variant<>(Arrays.asList("ccmp"), "as").getValue()); + thenResultingBuildAllMapContains("802-11-wireless-security", "pairwise", + new Variant<>(Arrays.asList("ccmp"), "as").getValue()); + } + + @Test + public void buildSettingsShouldWorkWithExpectedConfiguredForInputsWiFiWanIp6() { + givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusDisabled"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledWAN"); + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodManual"); + givenMapWith("net.interface.wlan0.config.ip6.address", "fe80::eed:f0a1:d03a:1028"); + givenMapWith("net.interface.wlan0.config.ip6.prefix", (short) 25); + givenMapWith("net.interface.wlan0.config.ip6.dnsServers", "2001:4860:4860:0:0:0:0:8844"); + givenMapWith("net.interface.wlan0.config.ip6.gateway", "fe80::eed:f0a1:d03a:1"); + givenMapWith("net.interface.wlan0.config.wifi.mode", "INFRA"); + givenMapWith("net.interface.wlan0.config.wifi.infra.ssid", "ssidtest"); + givenMapWith("net.interface.wlan0.config.wifi.infra.radioMode", "RADIO_MODE_80211a"); + givenMapWith("net.interface.wlan0.config.wifi.infra.channel", "10"); + givenMapWith("net.interface.wlan0.config.wifi.mode", "INFRA"); + givenMapWith("net.interface.wlan0.config.wifi.infra.passphrase", new Password("test")); + givenMapWith("net.interface.wlan0.config.wifi.infra.securityType", "SECURITY_WPA_WPA2"); + givenMapWith("net.interface.wlan0.config.wifi.infra.groupCiphers", "CCMP"); + givenMapWith("net.interface.wlan0.config.wifi.infra.pairwiseCiphers", "CCMP"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "wlan0", "wlan0", + NMDeviceType.NM_DEVICE_TYPE_WIFI); + + thenNoExceptionsHaveBeenThrown(); + thenResultingBuildAllMapContains("ipv4", "method", "disabled"); + thenResultingBuildAllMapContains("ipv6", "method", "manual"); + thenResultingBuildAllMapContains("ipv6", "address-data", + buildAddressDataWith("fe80::eed:f0a1:d03a:1028", new UInt32(25))); + thenResultingBuildAllMapContains("connection", "id", "kura-wlan0-connection"); + thenResultingBuildAllMapContains("connection", "interface-name", "wlan0"); + thenResultingBuildAllMapContains("connection", "type", "802-11-wireless"); + thenResultingBuildAllMapContains("802-11-wireless", "mode", "infrastructure"); + thenResultingBuildAllMapContainsBytes("802-11-wireless", "ssid", "ssidtest"); + thenResultingBuildAllMapContains("802-11-wireless", "band", "a"); + thenResultingBuildAllMapContains("802-11-wireless", "channel", new UInt32(Short.parseShort("10"))); + thenResultingBuildAllMapContains("802-11-wireless-security", "psk", new Password("test").toString()); + thenResultingBuildAllMapContains("802-11-wireless-security", "key-mgmt", "wpa-psk"); + thenResultingBuildAllMapContains("802-11-wireless-security", "group", + new Variant<>(Arrays.asList("ccmp"), "as").getValue()); + thenResultingBuildAllMapContains("802-11-wireless-security", "pairwise", + new Variant<>(Arrays.asList("ccmp"), "as").getValue()); + } + + @Test + public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiLanAndHiddenSsidIp6() { + givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusDisabled"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledLAN"); + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodManual"); + givenMapWith("net.interface.wlan0.config.ip6.address", "fe80::eed:f0a1:d03a:1028"); + givenMapWith("net.interface.wlan0.config.ip6.prefix", (short) 25); + givenMapWith("net.interface.wlan0.config.ip6.dnsServers", "2001:4860:4860:0:0:0:0:8844"); + givenMapWith("net.interface.wlan0.config.ip6.gateway", "fe80::eed:f0a1:d03a:1"); + givenMapWith("net.interface.wlan0.config.wifi.mode", "INFRA"); + givenMapWith("net.interface.wlan0.config.wifi.infra.ssid", "ssidtest"); + givenMapWith("net.interface.wlan0.config.wifi.infra.radioMode", "RADIO_MODE_80211a"); + givenMapWith("net.interface.wlan0.config.wifi.infra.channel", "10"); + givenMapWith("net.interface.wlan0.config.wifi.infra.ignoreSSID", true); + givenMapWith("net.interface.wlan0.config.wifi.mode", "INFRA"); + givenMapWith("net.interface.wlan0.config.wifi.infra.passphrase", new Password("test")); + givenMapWith("net.interface.wlan0.config.wifi.infra.securityType", "SECURITY_WPA_WPA2"); + givenMapWith("net.interface.wlan0.config.wifi.infra.groupCiphers", "CCMP"); + givenMapWith("net.interface.wlan0.config.wifi.infra.pairwiseCiphers", "CCMP"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "wlan0", "wlan0", + NMDeviceType.NM_DEVICE_TYPE_WIFI); + + thenNoExceptionsHaveBeenThrown(); + thenResultingBuildAllMapContains("ipv4", "method", "disabled"); + thenResultingBuildAllMapContains("ipv6", "method", "manual"); + thenResultingBuildAllMapContains("ipv6", "address-data", + buildAddressDataWith("fe80::eed:f0a1:d03a:1028", new UInt32(25))); + thenResultingBuildAllMapContains("connection", "id", "kura-wlan0-connection"); + thenResultingBuildAllMapContains("connection", "interface-name", "wlan0"); + thenResultingBuildAllMapContains("connection", "type", "802-11-wireless"); + thenResultingBuildAllMapContains("802-11-wireless", "mode", "infrastructure"); + thenResultingBuildAllMapContainsBytes("802-11-wireless", "ssid", "ssidtest"); + thenResultingBuildAllMapContains("802-11-wireless", "band", "a"); + thenResultingBuildAllMapContains("802-11-wireless", "channel", new UInt32(Short.parseShort("10"))); + thenResultingBuildAllMapContains("802-11-wireless", "hidden", true); + thenResultingBuildAllMapContains("802-11-wireless-security", "psk", new Password("test").toString()); + thenResultingBuildAllMapContains("802-11-wireless-security", "key-mgmt", "wpa-psk"); + thenResultingBuildAllMapContains("802-11-wireless-security", "group", + new Variant<>(Arrays.asList("ccmp"), "as").getValue()); + thenResultingBuildAllMapContains("802-11-wireless-security", "pairwise", + new Variant<>(Arrays.asList("ccmp"), "as").getValue()); + } + + @Test + public void buildSettingsShouldNotSet80211WirelessSecuritySettingsIfSecurityTypeIsSetToNoneIp6() { + givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusDisabled"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledLAN"); + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodManual"); + givenMapWith("net.interface.wlan0.config.ip6.address", "fe80::eed:f0a1:d03a:1028"); + givenMapWith("net.interface.wlan0.config.ip6.prefix", (short) 25); + givenMapWith("net.interface.wlan0.config.ip6.dnsServers", "2001:4860:4860:0:0:0:0:8844"); + givenMapWith("net.interface.wlan0.config.ip6.gateway", "fe80::eed:f0a1:d03a:1"); + givenMapWith("net.interface.wlan0.config.wifi.mode", "INFRA"); + givenMapWith("net.interface.wlan0.config.wifi.infra.ssid", "ssidtest"); + givenMapWith("net.interface.wlan0.config.wifi.infra.radioMode", "RADIO_MODE_80211a"); + givenMapWith("net.interface.wlan0.config.wifi.infra.channel", "10"); + givenMapWith("net.interface.wlan0.config.wifi.infra.securityType", "NONE"); + givenMapWith("net.interface.wlan0.config.wifi.infra.ignoreSSID", true); + givenMapWith("net.interface.wlan0.config.wifi.infra.passphrase", new Password("test")); + givenMapWith("net.interface.wlan0.config.wifi.infra.groupCiphers", "CCMP"); + givenMapWith("net.interface.wlan0.config.wifi.infra.pairwiseCiphers", "CCMP"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "wlan0", "wlan0", + NMDeviceType.NM_DEVICE_TYPE_WIFI); + + thenNoExceptionsHaveBeenThrown(); + thenResultingBuildAllMapContains("ipv4", "method", "disabled"); + thenResultingBuildAllMapContains("ipv6", "method", "manual"); + thenResultingBuildAllMapContains("ipv6", "address-data", + buildAddressDataWith("fe80::eed:f0a1:d03a:1028", new UInt32(25))); + thenResultingBuildAllMapNotContains("ipv6", "gateway"); + thenResultingBuildAllMapNotContains("ipv6", "dns"); + thenResultingBuildAllMapContains("ipv6", "ignore-auto-dns", true); + thenResultingBuildAllMapContains("ipv6", "ignore-auto-routes", true); + thenResultingBuildAllMapContains("connection", "id", "kura-wlan0-connection"); + thenResultingBuildAllMapContains("connection", "interface-name", "wlan0"); + thenResultingBuildAllMapContains("connection", "type", "802-11-wireless"); + thenResultingBuildAllMapContains("802-11-wireless", "mode", "infrastructure"); + thenResultingBuildAllMapContainsBytes("802-11-wireless", "ssid", "ssidtest"); + thenResultingBuildAllMapContains("802-11-wireless", "band", "a"); + thenResultingBuildAllMapContains("802-11-wireless", "channel", new UInt32(Short.parseShort("10"))); + thenResultingBuildAllMapNotContains("802-11-wireless-security"); + } + + @Test + public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiWanAndHiddenSsidIp6() { + givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusDisabled"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledWAN"); + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodManual"); + givenMapWith("net.interface.wlan0.config.ip6.address", "fe80::eed:f0a1:d03a:1028"); + givenMapWith("net.interface.wlan0.config.ip6.prefix", (short) 25); + givenMapWith("net.interface.wlan0.config.ip6.dnsServers", "2001:4860:4860:0:0:0:0:8844"); + givenMapWith("net.interface.wlan0.config.ip6.gateway", "fe80::eed:f0a1:d03a:1"); + givenMapWith("net.interface.wlan0.config.wifi.mode", "INFRA"); + givenMapWith("net.interface.wlan0.config.wifi.infra.ssid", "ssidtest"); + givenMapWith("net.interface.wlan0.config.wifi.infra.radioMode", "RADIO_MODE_80211a"); + givenMapWith("net.interface.wlan0.config.wifi.infra.channel", "10"); + givenMapWith("net.interface.wlan0.config.wifi.infra.ignoreSSID", true); + givenMapWith("net.interface.wlan0.config.wifi.mode", "INFRA"); + givenMapWith("net.interface.wlan0.config.wifi.infra.passphrase", new Password("test")); + givenMapWith("net.interface.wlan0.config.wifi.infra.securityType", "SECURITY_WPA_WPA2"); + givenMapWith("net.interface.wlan0.config.wifi.infra.groupCiphers", "CCMP"); + givenMapWith("net.interface.wlan0.config.wifi.infra.pairwiseCiphers", "CCMP"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "wlan0", "wlan0", + NMDeviceType.NM_DEVICE_TYPE_WIFI); + + thenNoExceptionsHaveBeenThrown(); + thenResultingBuildAllMapContains("ipv4", "method", "disabled"); + thenResultingBuildAllMapContains("ipv6", "method", "manual"); + thenResultingBuildAllMapContains("ipv6", "address-data", + buildAddressDataWith("fe80::eed:f0a1:d03a:1028", new UInt32(25))); + thenResultingBuildAllMapNotContains("ipv6", "ignore-auto-routes"); + thenResultingBuildAllMapContains("ipv6", "ignore-auto-dns", true); + thenResultingBuildAllMapContains("connection", "id", "kura-wlan0-connection"); + thenResultingBuildAllMapContains("connection", "interface-name", "wlan0"); + thenResultingBuildAllMapContains("connection", "type", "802-11-wireless"); + thenResultingBuildAllMapContains("802-11-wireless", "mode", "infrastructure"); + thenResultingBuildAllMapContainsBytes("802-11-wireless", "ssid", "ssidtest"); + thenResultingBuildAllMapContains("802-11-wireless", "band", "a"); + thenResultingBuildAllMapContains("802-11-wireless", "channel", new UInt32(Short.parseShort("10"))); + thenResultingBuildAllMapContains("802-11-wireless", "hidden", true); + thenResultingBuildAllMapContains("802-11-wireless-security", "psk", new Password("test").toString()); + thenResultingBuildAllMapContains("802-11-wireless-security", "key-mgmt", "wpa-psk"); + thenResultingBuildAllMapContains("802-11-wireless-security", "group", + new Variant<>(Arrays.asList("ccmp"), "as").getValue()); + thenResultingBuildAllMapContains("802-11-wireless-security", "pairwise", + new Variant<>(Arrays.asList("ccmp"), "as").getValue()); + } + + @Test + public void buildSettingsShouldWorkWithExpectedInputsConfiguredForEthernetAndUnmanagedIp6() { + givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusDisabled"); + givenMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusUnmanaged"); + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodManual"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "eth0", "eth0", + NMDeviceType.NM_DEVICE_TYPE_ETHERNET); + + thenIllegalArgumentExceptionThrown(); + } + + @Test + public void buildSettingsShouldWorkWithExpectedInputsConfiguredForEthernetAndLanIp6() { + givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusDisabled"); + givenMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusEnabledLAN"); + givenMapWith("net.interface.eth0.config.ip6.address.method", "netIPv6MethodManual"); + givenMapWith("net.interface.eth0.config.ip6.address", "fe80::eed:f0a1:d03a:1028"); + givenMapWith("net.interface.eth0.config.ip6.prefix", (short) 25); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "eth0", "eth0", + NMDeviceType.NM_DEVICE_TYPE_ETHERNET); + + thenNoExceptionsHaveBeenThrown(); + thenResultingBuildAllMapContains("ipv4", "method", "disabled"); + thenResultingBuildAllMapContains("ipv6", "method", "manual"); + thenResultingBuildAllMapContains("ipv6", "address-data", + buildAddressDataWith("fe80::eed:f0a1:d03a:1028", new UInt32(25))); + thenResultingBuildAllMapContains("ipv6", "ignore-auto-dns", true); + thenResultingBuildAllMapContains("ipv6", "ignore-auto-routes", true); + thenResultingBuildAllMapNotContains("ipv6", "gateway"); + thenResultingBuildAllMapNotContains("ipv6", "dns"); + thenResultingBuildAllMapContains("connection", "id", "kura-eth0-connection"); + thenResultingBuildAllMapContains("connection", "interface-name", "eth0"); + thenResultingBuildAllMapContains("connection", "type", "802-3-ethernet"); + } + + @Test + public void buildSettingsShouldWorkWithExpectedInputsEthernetAndWanIp6() { + givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusDisabled"); + givenMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusEnabledWAN"); + givenMapWith("net.interface.eth0.config.ip6.address.method", "netIPv6MethodManual"); + givenMapWith("net.interface.eth0.config.ip6.address", "fe80::eed:f0a1:d03a:1028"); + givenMapWith("net.interface.eth0.config.ip6.prefix", (short) 25); + givenMapWith("net.interface.eth0.config.ip6.dnsServers", "2001:4860:4860:0:0:0:0:8844"); + givenMapWith("net.interface.eth0.config.ip6.gateway", "fe80::eed:f0a1:d03a:1"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "eth0", "eth0", + NMDeviceType.NM_DEVICE_TYPE_ETHERNET); + + thenNoExceptionsHaveBeenThrown(); + thenResultingBuildAllMapContains("ipv4", "method", "disabled"); + thenResultingBuildAllMapContains("ipv6", "method", "manual"); + thenResultingBuildAllMapContains("ipv6", "address-data", + buildAddressDataWith("fe80::eed:f0a1:d03a:1028", new UInt32(25))); + thenResultingBuildAllMapContains("ipv6", "gateway", "fe80::eed:f0a1:d03a:1"); + thenResultingBuildAllMapContains("ipv6", "dns", Arrays.asList(IP6_BYTE_ARRAY_ADDRESS)); + thenResultingBuildAllMapContains("ipv6", "ignore-auto-dns", true); + thenResultingBuildAllMapNotContains("ipv6", "ignore-auto-routes"); + thenResultingBuildAllMapContains("connection", "id", "kura-eth0-connection"); + thenResultingBuildAllMapContains("connection", "interface-name", "eth0"); + thenResultingBuildAllMapContains("connection", "type", "802-3-ethernet"); + } + + @Test + public void buildSettingsShouldWorkWithModemSettingsIp6() { + givenMapWith("net.interface.1-1.1.config.ip4.status", "netIPv4StatusDisabled"); + givenMapWith("net.interface.1-1.1.config.ip6.status", "netIPv6StatusEnabledWAN"); + givenMapWith("net.interface.1-1.1.config.ip6.address.method", "netIPv6MethodAuto"); + givenMapWith("net.interface.1-1.1.config.apn", "mobile.test.com"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "1-1.1", "ttyACM0", + NMDeviceType.NM_DEVICE_TYPE_MODEM); + + thenNoExceptionsHaveBeenThrown(); + thenResultingBuildAllMapContains("ipv6", "method", "auto"); + thenResultingBuildAllMapContains("ipv4", "method", "disabled"); + thenResultingBuildAllMapContains("connection", "id", "kura-ttyACM0-connection"); + thenResultingBuildAllMapContains("connection", "interface-name", "ttyACM0"); + thenResultingBuildAllMapContains("connection", "type", "gsm"); + thenResultingBuildAllMapContains("connection", "autoconnect-retries", 1); + thenResultingBuildAllMapContains("gsm", "apn", "mobile.test.com"); + } + + @Test + public void buildSettingsShouldThrowWithManualAndNullIpIp6() { + givenMapWith("net.interface.eth0.config.ip4.status", "netIPv6StatusDisabled"); + givenMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusEnabledWAN"); + givenMapWith("net.interface.eth0.config.ip6.address.method", "netIPv6MethodManual"); + givenMapWith("net.interface.eth0.config.ip6.address", null); + givenMapWith("net.interface.eth0.config.ip6.prefix", (short) 25); + givenMapWith("net.interface.eth0.config.ip6.dnsServers", "2001:4860:4860:0:0:0:0:8844"); + givenMapWith("net.interface.eth0.config.ip6.gateway", "fe80::eed:f0a1:d03a:1"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "eth0", "eth0", + NMDeviceType.NM_DEVICE_TYPE_ETHERNET); + + thenNoSuchElementExceptionThrown(); + } + + @Test + public void buildSettingsShouldThrowWithManualAndNullPrefixIp6() { + givenMapWith("net.interface.eth0.config.ip4.status", "netIPv6StatusDisabled"); + givenMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusEnabledWAN"); + givenMapWith("net.interface.eth0.config.ip6.address.method", "netIPv6MethodManual"); + givenMapWith("net.interface.eth0.config.ip6.address", "fe80::eed:f0a1:d03a:1028"); + givenMapWith("net.interface.eth0.config.ip6.prefix", null); + givenMapWith("net.interface.eth0.config.ip6.dnsServers", "2001:4860:4860:0:0:0:0:8844"); + givenMapWith("net.interface.eth0.config.ip6.gateway", "fe80::eed:f0a1:d03a:1"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "eth0", "eth0", + NMDeviceType.NM_DEVICE_TYPE_ETHERNET); + + thenNoSuchElementExceptionThrown(); + } + + @Test + public void buildSettingsShouldWorkWithManualAndNullStatusIp6() { + givenMapWith("net.interface.eth0.config.ip4.status", "netIPv6StatusDisabled"); + givenMapWith("net.interface.eth0.config.ip6.status", null); + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodManual"); + givenMapWith("net.interface.eth0.config.ip6.address", "fe80::eed:f0a1:d03a:1028"); + givenMapWith("net.interface.eth0.config.ip6.prefix", (short) 25); + givenMapWith("net.interface.eth0.config.ip6.dnsServers", "2001:4860:4860:0:0:0:0:8844"); + givenMapWith("net.interface.eth0.config.ip6.gateway", "fe80::eed:f0a1:d03a:1"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "eth0", "eth0", + NMDeviceType.NM_DEVICE_TYPE_ETHERNET); + + thenResultingBuildAllMapContains("ipv6", "method", "disabled"); + } + + @Test + public void buildSettingsShouldThrowWithManualAndNullWifiSsidIp6() { + givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusDisabled"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledWAN"); + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodManual"); + givenMapWith("net.interface.wlan0.config.ip6.address", "fe80::eed:f0a1:d03a:1028"); + givenMapWith("net.interface.wlan0.config.ip6.prefix", (short) 25); + givenMapWith("net.interface.wlan0.config.ip6.dnsServers", "2001:4860:4860:0:0:0:0:8844"); + givenMapWith("net.interface.wlan0.config.ip6.gateway", "fe80::eed:f0a1:d03a:1"); + givenMapWith("net.interface.wlan0.config.wifi.mode", "INFRA"); + givenMapWith("net.interface.wlan0.config.wifi.infra.ssid", null); + givenMapWith("net.interface.wlan0.config.wifi.infra.radioMode", "RADIO_MODE_80211a"); + givenMapWith("net.interface.wlan0.config.wifi.infra.channel", "10"); + givenMapWith("net.interface.wlan0.config.wifi.infra.ignoreSSID", true); + givenMapWith("net.interface.wlan0.config.wifi.mode", "INFRA"); + givenMapWith("net.interface.wlan0.config.wifi.infra.passphrase", new Password("test")); + givenMapWith("net.interface.wlan0.config.wifi.infra.securityType", "SECURITY_WPA_WPA2"); + givenMapWith("net.interface.wlan0.config.wifi.infra.groupCiphers", "CCMP"); + givenMapWith("net.interface.wlan0.config.wifi.infra.pairwiseCiphers", "CCMP"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "wlan0", "wlan0", + NMDeviceType.NM_DEVICE_TYPE_WIFI); + + thenNoSuchElementExceptionThrown(); + } + + @Test + public void buildSettingsShouldThrowWithManualAndNullWifiPasswordIp6() { + givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusDisabled"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledWAN"); + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodManual"); + givenMapWith("net.interface.wlan0.config.ip6.address", "fe80::eed:f0a1:d03a:1028"); + givenMapWith("net.interface.wlan0.config.ip6.prefix", (short) 25); + givenMapWith("net.interface.wlan0.config.ip6.dnsServers", "2001:4860:4860:0:0:0:0:8844"); + givenMapWith("net.interface.wlan0.config.ip6.gateway", "fe80::eed:f0a1:d03a:1"); + givenMapWith("net.interface.wlan0.config.wifi.mode", "INFRA"); + givenMapWith("net.interface.wlan0.config.wifi.infra.ssid", "ssidtest"); + givenMapWith("net.interface.wlan0.config.wifi.infra.radioMode", null); + givenMapWith("net.interface.wlan0.config.wifi.infra.channel", "10"); + givenMapWith("net.interface.wlan0.config.wifi.infra.ignoreSSID", true); + givenMapWith("net.interface.wlan0.config.wifi.mode", "INFRA"); + givenMapWith("net.interface.wlan0.config.wifi.infra.passphrase", null); + givenMapWith("net.interface.wlan0.config.wifi.infra.securityType", "SECURITY_WPA_WPA2"); + givenMapWith("net.interface.wlan0.config.wifi.infra.groupCiphers", "CCMP"); + givenMapWith("net.interface.wlan0.config.wifi.infra.pairwiseCiphers", "CCMP"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "wlan0", "wlan0", + NMDeviceType.NM_DEVICE_TYPE_WIFI); + + thenNoSuchElementExceptionThrown(); + } + + @Test + public void buildSettingsShouldThrowWithManualAndNullWifiSecurityTypeIp6() { + givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusDisabled"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledWAN"); + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodManual"); + givenMapWith("net.interface.wlan0.config.ip6.address", "fe80::eed:f0a1:d03a:1028"); + givenMapWith("net.interface.wlan0.config.ip6.prefix", (short) 25); + givenMapWith("net.interface.wlan0.config.ip6.dnsServers", "2001:4860:4860:0:0:0:0:8844"); + givenMapWith("net.interface.wlan0.config.ip6.gateway", "fe80::eed:f0a1:d03a:1"); + givenMapWith("net.interface.wlan0.config.wifi.mode", "INFRA"); + givenMapWith("net.interface.wlan0.config.wifi.infra.ssid", "ssidtest"); + givenMapWith("net.interface.wlan0.config.wifi.infra.radioMode", "RADIO_MODE_80211a"); + givenMapWith("net.interface.wlan0.config.wifi.infra.channel", "10"); + givenMapWith("net.interface.wlan0.config.wifi.infra.ignoreSSID", true); + givenMapWith("net.interface.wlan0.config.wifi.mode", "INFRA"); + givenMapWith("net.interface.wlan0.config.wifi.infra.passphrase", new Password("test")); + givenMapWith("net.interface.wlan0.config.wifi.infra.securityType", null); + givenMapWith("net.interface.wlan0.config.wifi.infra.groupCiphers", "CCMP"); + givenMapWith("net.interface.wlan0.config.wifi.infra.pairwiseCiphers", "CCMP"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "wlan0", "wlan0", + NMDeviceType.NM_DEVICE_TYPE_WIFI); + + thenNoSuchElementExceptionThrown(); + } + + @Test + public void buildSettingsShouldThrowWithStatusUnmanagedIp4AndIp6() { + givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusUnmanaged"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusUnmanaged"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "wlan0", "wlan0", + NMDeviceType.NM_DEVICE_TYPE_WIFI); + + thenIllegalArgumentExceptionThrown(); + } + + @Test + public void buildSettingsShouldThrowWithStatusUnknownIp4AndIp6() { + givenMapWith("net.interface.wlan0.config.ip4.status", "myAwesomeUnknownString"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusUnknown"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "wlan0", "wlan0", + NMDeviceType.NM_DEVICE_TYPE_WIFI); + + thenIllegalArgumentExceptionThrown(); + } + + @Test + public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiUnmangedIp4AndIp6() { + givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); + givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusUnmanaged"); + givenMapWith("net.interface.wlan0.config.ip4.address", "192.168.0.12"); + givenMapWith("net.interface.wlan0.config.ip4.prefix", (short) 25); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusUnmanaged"); + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodManual"); + givenMapWith("net.interface.wlan0.config.ip6.address", "fe80::eed:f0a1:d03a:1028"); + givenMapWith("net.interface.wlan0.config.ip6.prefix", (short) 25); + givenMapWith("net.interface.wlan0.config.ip6.dnsServers", "2001:4860:4860:0:0:0:0:8844"); + givenMapWith("net.interface.wlan0.config.ip6.gateway", "fe80::eed:f0a1:d03a:1"); + givenMapWith("net.interface.wlan0.config.wifi.mode", "INFRA"); + givenMapWith("net.interface.wlan0.config.wifi.infra.ssid", "ssidtest"); + givenMapWith("net.interface.wlan0.config.wifi.infra.radioMode", "RADIO_MODE_80211a"); + givenMapWith("net.interface.wlan0.config.wifi.infra.channel", "10"); + givenMapWith("net.interface.wlan0.config.wifi.mode", "INFRA"); + givenMapWith("net.interface.wlan0.config.wifi.infra.passphrase", new Password("test")); + givenMapWith("net.interface.wlan0.config.wifi.infra.securityType", "SECURITY_WPA_WPA2"); + givenMapWith("net.interface.wlan0.config.wifi.infra.groupCiphers", "CCMP"); + givenMapWith("net.interface.wlan0.config.wifi.infra.pairwiseCiphers", "CCMP"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "wlan0", "wlan0", + NMDeviceType.NM_DEVICE_TYPE_WIFI); + + thenIllegalArgumentExceptionThrown(); + } + + @Test + public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiLanIp4AndIp6() { + givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); + givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusEnabledLAN"); + givenMapWith("net.interface.wlan0.config.ip4.address", "192.168.0.12"); + givenMapWith("net.interface.wlan0.config.ip4.prefix", (short) 25); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledLAN"); + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodManual"); + givenMapWith("net.interface.wlan0.config.ip6.address", "fe80::eed:f0a1:d03a:1028"); + givenMapWith("net.interface.wlan0.config.ip6.prefix", (short) 25); + givenMapWith("net.interface.wlan0.config.ip6.dnsServers", "2001:4860:4860:0:0:0:0:8844"); + givenMapWith("net.interface.wlan0.config.ip6.gateway", "fe80::eed:f0a1:d03a:1"); + givenMapWith("net.interface.wlan0.config.wifi.mode", "INFRA"); + givenMapWith("net.interface.wlan0.config.wifi.infra.ssid", "ssidtest"); + givenMapWith("net.interface.wlan0.config.wifi.infra.radioMode", "RADIO_MODE_80211a"); + givenMapWith("net.interface.wlan0.config.wifi.infra.channel", "10"); + givenMapWith("net.interface.wlan0.config.wifi.mode", "INFRA"); + givenMapWith("net.interface.wlan0.config.wifi.infra.passphrase", new Password("test")); + givenMapWith("net.interface.wlan0.config.wifi.infra.securityType", "SECURITY_WPA_WPA2"); + givenMapWith("net.interface.wlan0.config.wifi.infra.groupCiphers", "CCMP"); + givenMapWith("net.interface.wlan0.config.wifi.infra.pairwiseCiphers", "CCMP"); + + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "wlan0", "wlan0", + NMDeviceType.NM_DEVICE_TYPE_WIFI); + + thenNoExceptionsHaveBeenThrown(); + thenResultingBuildAllMapContains("ipv4", "method", "manual"); + thenResultingBuildAllMapContains("ipv4", "address-data", buildAddressDataWith("192.168.0.12", new UInt32(25))); + thenResultingBuildAllMapNotContains("ipv4", "gateway"); + thenResultingBuildAllMapNotContains("ipv4", "dns"); + thenResultingBuildAllMapContains("ipv4", "ignore-auto-dns", true); + thenResultingBuildAllMapContains("ipv4", "ignore-auto-routes", true); + thenResultingBuildAllMapContains("ipv6", "method", "manual"); + thenResultingBuildAllMapContains("ipv6", "address-data", + buildAddressDataWith("fe80::eed:f0a1:d03a:1028", new UInt32(25))); + thenResultingBuildAllMapContains("connection", "id", "kura-wlan0-connection"); + thenResultingBuildAllMapContains("connection", "interface-name", "wlan0"); + thenResultingBuildAllMapContains("connection", "type", "802-11-wireless"); + thenResultingBuildAllMapContains("802-11-wireless", "mode", "infrastructure"); + thenResultingBuildAllMapContainsBytes("802-11-wireless", "ssid", "ssidtest"); + thenResultingBuildAllMapContains("802-11-wireless", "band", "a"); + thenResultingBuildAllMapContains("802-11-wireless", "channel", new UInt32(Short.parseShort("10"))); + thenResultingBuildAllMapContains("802-11-wireless-security", "psk", new Password("test").toString()); + thenResultingBuildAllMapContains("802-11-wireless-security", "key-mgmt", "wpa-psk"); + thenResultingBuildAllMapContains("802-11-wireless-security", "group", + new Variant<>(Arrays.asList("ccmp"), "as").getValue()); + thenResultingBuildAllMapContains("802-11-wireless-security", "pairwise", + new Variant<>(Arrays.asList("ccmp"), "as").getValue()); + } + + @Test + public void buildSettingsShouldWorkWithExpectedConfiguredForInputsWiFiWanIp4AndIp6() { + givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); + givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusEnabledWAN"); + givenMapWith("net.interface.wlan0.config.ip4.address", "192.168.0.12"); + givenMapWith("net.interface.wlan0.config.ip4.prefix", (short) 25); + givenMapWith("net.interface.wlan0.config.ip4.dnsServers", "1.1.1.1"); + givenMapWith("net.interface.wlan0.config.ip4.gateway", "192.168.0.1"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledWAN"); + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodManual"); + givenMapWith("net.interface.wlan0.config.ip6.address", "fe80::eed:f0a1:d03a:1028"); + givenMapWith("net.interface.wlan0.config.ip6.prefix", (short) 25); + givenMapWith("net.interface.wlan0.config.ip6.dnsServers", "2001:4860:4860:0:0:0:0:8844"); + givenMapWith("net.interface.wlan0.config.ip6.gateway", "fe80::eed:f0a1:d03a:1"); + givenMapWith("net.interface.wlan0.config.wifi.mode", "INFRA"); + givenMapWith("net.interface.wlan0.config.wifi.infra.ssid", "ssidtest"); + givenMapWith("net.interface.wlan0.config.wifi.infra.radioMode", "RADIO_MODE_80211a"); + givenMapWith("net.interface.wlan0.config.wifi.infra.channel", "10"); + givenMapWith("net.interface.wlan0.config.wifi.mode", "INFRA"); + givenMapWith("net.interface.wlan0.config.wifi.infra.passphrase", new Password("test")); + givenMapWith("net.interface.wlan0.config.wifi.infra.securityType", "SECURITY_WPA_WPA2"); + givenMapWith("net.interface.wlan0.config.wifi.infra.groupCiphers", "CCMP"); + givenMapWith("net.interface.wlan0.config.wifi.infra.pairwiseCiphers", "CCMP"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "wlan0", "wlan0", + NMDeviceType.NM_DEVICE_TYPE_WIFI); + + thenNoExceptionsHaveBeenThrown(); + thenResultingBuildAllMapContains("ipv4", "method", "manual"); + thenResultingBuildAllMapContains("ipv4", "address-data", buildAddressDataWith("192.168.0.12", new UInt32(25))); + thenResultingBuildAllMapContains("ipv4", "ignore-auto-dns", true); + thenResultingBuildAllMapContains("ipv4", "dns", + new Variant<>(Arrays.asList(new UInt32(16843009)), "au").getValue()); + thenResultingBuildAllMapContains("ipv4", "gateway", "192.168.0.1"); + thenResultingBuildAllMapContains("ipv6", "method", "manual"); + thenResultingBuildAllMapContains("ipv6", "address-data", + buildAddressDataWith("fe80::eed:f0a1:d03a:1028", new UInt32(25))); + thenResultingBuildAllMapContains("connection", "id", "kura-wlan0-connection"); + thenResultingBuildAllMapContains("connection", "interface-name", "wlan0"); + thenResultingBuildAllMapContains("connection", "type", "802-11-wireless"); + thenResultingBuildAllMapContains("802-11-wireless", "mode", "infrastructure"); + thenResultingBuildAllMapContainsBytes("802-11-wireless", "ssid", "ssidtest"); + thenResultingBuildAllMapContains("802-11-wireless", "band", "a"); + thenResultingBuildAllMapContains("802-11-wireless", "channel", new UInt32(Short.parseShort("10"))); + thenResultingBuildAllMapContains("802-11-wireless-security", "psk", new Password("test").toString()); + thenResultingBuildAllMapContains("802-11-wireless-security", "key-mgmt", "wpa-psk"); + thenResultingBuildAllMapContains("802-11-wireless-security", "group", + new Variant<>(Arrays.asList("ccmp"), "as").getValue()); + thenResultingBuildAllMapContains("802-11-wireless-security", "pairwise", + new Variant<>(Arrays.asList("ccmp"), "as").getValue()); + } + + @Test + public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiLanAndHiddenSsidIp4AndIp6() { + givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); + givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusEnabledLAN"); + givenMapWith("net.interface.wlan0.config.ip4.address", "192.168.0.12"); + givenMapWith("net.interface.wlan0.config.ip4.prefix", (short) 25); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledLAN"); + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodManual"); + givenMapWith("net.interface.wlan0.config.ip6.address", "fe80::eed:f0a1:d03a:1028"); + givenMapWith("net.interface.wlan0.config.ip6.prefix", (short) 25); + givenMapWith("net.interface.wlan0.config.wifi.mode", "INFRA"); + givenMapWith("net.interface.wlan0.config.wifi.infra.ssid", "ssidtest"); + givenMapWith("net.interface.wlan0.config.wifi.infra.radioMode", "RADIO_MODE_80211a"); + givenMapWith("net.interface.wlan0.config.wifi.infra.channel", "10"); + givenMapWith("net.interface.wlan0.config.wifi.infra.ignoreSSID", true); + givenMapWith("net.interface.wlan0.config.wifi.mode", "INFRA"); + givenMapWith("net.interface.wlan0.config.wifi.infra.passphrase", new Password("test")); + givenMapWith("net.interface.wlan0.config.wifi.infra.securityType", "SECURITY_WPA_WPA2"); + givenMapWith("net.interface.wlan0.config.wifi.infra.groupCiphers", "CCMP"); + givenMapWith("net.interface.wlan0.config.wifi.infra.pairwiseCiphers", "CCMP"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "wlan0", "wlan0", + NMDeviceType.NM_DEVICE_TYPE_WIFI); + + thenNoExceptionsHaveBeenThrown(); + thenResultingBuildAllMapContains("ipv4", "method", "manual"); + thenResultingBuildAllMapContains("ipv4", "address-data", buildAddressDataWith("192.168.0.12", new UInt32(25))); + thenResultingBuildAllMapNotContains("ipv4", "gateway"); + thenResultingBuildAllMapNotContains("ipv4", "dns"); + thenResultingBuildAllMapContains("ipv4", "ignore-auto-dns", true); + thenResultingBuildAllMapContains("ipv4", "ignore-auto-routes", true); + thenResultingBuildAllMapContains("ipv6", "method", "manual"); + thenResultingBuildAllMapContains("ipv6", "address-data", + buildAddressDataWith("fe80::eed:f0a1:d03a:1028", new UInt32(25))); + thenResultingBuildAllMapContains("connection", "id", "kura-wlan0-connection"); + thenResultingBuildAllMapContains("connection", "interface-name", "wlan0"); + thenResultingBuildAllMapContains("connection", "type", "802-11-wireless"); + thenResultingBuildAllMapContains("802-11-wireless", "mode", "infrastructure"); + thenResultingBuildAllMapContainsBytes("802-11-wireless", "ssid", "ssidtest"); + thenResultingBuildAllMapContains("802-11-wireless", "band", "a"); + thenResultingBuildAllMapContains("802-11-wireless", "channel", new UInt32(Short.parseShort("10"))); + thenResultingBuildAllMapContains("802-11-wireless", "hidden", true); + thenResultingBuildAllMapContains("802-11-wireless-security", "psk", new Password("test").toString()); + thenResultingBuildAllMapContains("802-11-wireless-security", "key-mgmt", "wpa-psk"); + thenResultingBuildAllMapContains("802-11-wireless-security", "group", + new Variant<>(Arrays.asList("ccmp"), "as").getValue()); + thenResultingBuildAllMapContains("802-11-wireless-security", "pairwise", + new Variant<>(Arrays.asList("ccmp"), "as").getValue()); + } + + @Test + public void buildSettingsShouldNotSet80211WirelessSecuritySettingsIfSecurityTypeIsSetToNoneIp4AndIp6() { + givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); + givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusEnabledLAN"); + givenMapWith("net.interface.wlan0.config.ip4.address", "192.168.0.12"); + givenMapWith("net.interface.wlan0.config.ip4.prefix", (short) 25); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledLAN"); + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodManual"); + givenMapWith("net.interface.wlan0.config.ip6.address", "fe80::eed:f0a1:d03a:1028"); + givenMapWith("net.interface.wlan0.config.ip6.prefix", (short) 25); + givenMapWith("net.interface.wlan0.config.wifi.mode", "INFRA"); + givenMapWith("net.interface.wlan0.config.wifi.infra.ssid", "ssidtest"); + givenMapWith("net.interface.wlan0.config.wifi.infra.radioMode", "RADIO_MODE_80211a"); + givenMapWith("net.interface.wlan0.config.wifi.infra.channel", "10"); + givenMapWith("net.interface.wlan0.config.wifi.infra.securityType", "NONE"); + givenMapWith("net.interface.wlan0.config.wifi.infra.ignoreSSID", true); + givenMapWith("net.interface.wlan0.config.wifi.infra.passphrase", new Password("test")); + givenMapWith("net.interface.wlan0.config.wifi.infra.groupCiphers", "CCMP"); + givenMapWith("net.interface.wlan0.config.wifi.infra.pairwiseCiphers", "CCMP"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "wlan0", "wlan0", + NMDeviceType.NM_DEVICE_TYPE_WIFI); + + thenNoExceptionsHaveBeenThrown(); + thenResultingBuildAllMapContains("ipv4", "method", "manual"); + thenResultingBuildAllMapContains("ipv4", "address-data", buildAddressDataWith("192.168.0.12", new UInt32(25))); + thenResultingBuildAllMapNotContains("ipv4", "gateway"); + thenResultingBuildAllMapNotContains("ipv4", "dns"); + thenResultingBuildAllMapContains("ipv4", "ignore-auto-dns", true); + thenResultingBuildAllMapContains("ipv4", "ignore-auto-routes", true); + thenResultingBuildAllMapContains("ipv6", "method", "manual"); + thenResultingBuildAllMapContains("ipv6", "address-data", + buildAddressDataWith("fe80::eed:f0a1:d03a:1028", new UInt32(25))); + thenResultingBuildAllMapNotContains("ipv6", "gateway"); + thenResultingBuildAllMapNotContains("ipv6", "dns"); + thenResultingBuildAllMapContains("ipv6", "ignore-auto-dns", true); + thenResultingBuildAllMapContains("ipv6", "ignore-auto-routes", true); + thenResultingBuildAllMapContains("connection", "id", "kura-wlan0-connection"); + thenResultingBuildAllMapContains("connection", "interface-name", "wlan0"); + thenResultingBuildAllMapContains("connection", "type", "802-11-wireless"); + thenResultingBuildAllMapContains("802-11-wireless", "mode", "infrastructure"); + thenResultingBuildAllMapContainsBytes("802-11-wireless", "ssid", "ssidtest"); + thenResultingBuildAllMapContains("802-11-wireless", "band", "a"); + thenResultingBuildAllMapContains("802-11-wireless", "channel", new UInt32(Short.parseShort("10"))); + thenResultingBuildAllMapNotContains("802-11-wireless-security"); + } + + @Test + public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiWanAndHiddenSsidIp4AndIp6() { + givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); + givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusEnabledWAN"); + givenMapWith("net.interface.wlan0.config.ip4.address", "192.168.0.12"); + givenMapWith("net.interface.wlan0.config.ip4.prefix", (short) 25); + givenMapWith("net.interface.wlan0.config.ip4.dnsServers", "1.1.1.1"); + givenMapWith("net.interface.wlan0.config.ip4.gateway", "192.168.0.1"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledWAN"); + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodManual"); + givenMapWith("net.interface.wlan0.config.ip6.address", "fe80::eed:f0a1:d03a:1028"); + givenMapWith("net.interface.wlan0.config.ip6.prefix", (short) 25); + givenMapWith("net.interface.wlan0.config.ip6.dnsServers", "2001:4860:4860:0:0:0:0:8844"); + givenMapWith("net.interface.wlan0.config.ip6.gateway", "fe80::eed:f0a1:d03a:1"); + givenMapWith("net.interface.wlan0.config.wifi.mode", "INFRA"); + givenMapWith("net.interface.wlan0.config.wifi.infra.ssid", "ssidtest"); + givenMapWith("net.interface.wlan0.config.wifi.infra.radioMode", "RADIO_MODE_80211a"); + givenMapWith("net.interface.wlan0.config.wifi.infra.channel", "10"); + givenMapWith("net.interface.wlan0.config.wifi.infra.ignoreSSID", true); + givenMapWith("net.interface.wlan0.config.wifi.mode", "INFRA"); + givenMapWith("net.interface.wlan0.config.wifi.infra.passphrase", new Password("test")); + givenMapWith("net.interface.wlan0.config.wifi.infra.securityType", "SECURITY_WPA_WPA2"); + givenMapWith("net.interface.wlan0.config.wifi.infra.groupCiphers", "CCMP"); + givenMapWith("net.interface.wlan0.config.wifi.infra.pairwiseCiphers", "CCMP"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "wlan0", "wlan0", + NMDeviceType.NM_DEVICE_TYPE_WIFI); + + thenNoExceptionsHaveBeenThrown(); + thenResultingBuildAllMapContains("ipv4", "method", "manual"); + thenResultingBuildAllMapContains("ipv4", "address-data", buildAddressDataWith("192.168.0.12", new UInt32(25))); + thenResultingBuildAllMapContains("ipv4", "gateway", "192.168.0.1"); + thenResultingBuildAllMapContains("ipv4", "dns", + new Variant<>(Arrays.asList(new UInt32(16843009)), "au").getValue()); + thenResultingBuildAllMapContains("ipv4", "ignore-auto-dns", true); + thenResultingBuildAllMapNotContains("ipv4", "ignore-auto-routes"); + thenResultingBuildAllMapContains("ipv6", "method", "manual"); + thenResultingBuildAllMapContains("ipv6", "address-data", + buildAddressDataWith("fe80::eed:f0a1:d03a:1028", new UInt32(25))); + thenResultingBuildAllMapNotContains("ipv6", "ignore-auto-routes"); + thenResultingBuildAllMapContains("ipv6", "ignore-auto-dns", true); + thenResultingBuildAllMapContains("connection", "id", "kura-wlan0-connection"); + thenResultingBuildAllMapContains("connection", "interface-name", "wlan0"); + thenResultingBuildAllMapContains("connection", "type", "802-11-wireless"); + thenResultingBuildAllMapContains("802-11-wireless", "mode", "infrastructure"); + thenResultingBuildAllMapContainsBytes("802-11-wireless", "ssid", "ssidtest"); + thenResultingBuildAllMapContains("802-11-wireless", "band", "a"); + thenResultingBuildAllMapContains("802-11-wireless", "channel", new UInt32(Short.parseShort("10"))); + thenResultingBuildAllMapContains("802-11-wireless", "hidden", true); + thenResultingBuildAllMapContains("802-11-wireless-security", "psk", new Password("test").toString()); + thenResultingBuildAllMapContains("802-11-wireless-security", "key-mgmt", "wpa-psk"); + thenResultingBuildAllMapContains("802-11-wireless-security", "group", + new Variant<>(Arrays.asList("ccmp"), "as").getValue()); + thenResultingBuildAllMapContains("802-11-wireless-security", "pairwise", + new Variant<>(Arrays.asList("ccmp"), "as").getValue()); + } + + @Test + public void buildSettingsShouldWorkWithExpectedInputsConfiguredForEthernetAndUnmanagedIp4AndIp6() { + givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusUnmanaged"); + givenMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusUnmanaged"); + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodManual"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "eth0", "eth0", + NMDeviceType.NM_DEVICE_TYPE_ETHERNET); + + thenIllegalArgumentExceptionThrown(); + } + + @Test + public void buildSettingsShouldWorkWithExpectedInputsConfiguredForEthernetAndLanIp4AndIp6() { + givenMapWith("net.interface.eth0.config.dhcpClient4.enabled", false); + givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusEnabledLAN"); + givenMapWith("net.interface.eth0.config.ip4.address", "192.168.0.12"); + givenMapWith("net.interface.eth0.config.ip4.prefix", (short) 25); + givenMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusEnabledLAN"); + givenMapWith("net.interface.eth0.config.ip6.address.method", "netIPv6MethodManual"); + givenMapWith("net.interface.eth0.config.ip6.address", "fe80::eed:f0a1:d03a:1028"); + givenMapWith("net.interface.eth0.config.ip6.prefix", (short) 25); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "eth0", "eth0", + NMDeviceType.NM_DEVICE_TYPE_ETHERNET); + + thenNoExceptionsHaveBeenThrown(); + thenResultingBuildAllMapContains("ipv4", "method", "manual"); + thenResultingBuildAllMapContains("ipv4", "address-data", buildAddressDataWith("192.168.0.12", new UInt32(25))); + thenResultingBuildAllMapContains("ipv4", "ignore-auto-dns", true); + thenResultingBuildAllMapContains("ipv4", "ignore-auto-routes", true); + thenResultingBuildAllMapNotContains("ipv4", "gateway"); + thenResultingBuildAllMapNotContains("ipv4", "dns"); + thenResultingBuildAllMapContains("ipv6", "method", "manual"); + thenResultingBuildAllMapContains("ipv6", "address-data", + buildAddressDataWith("fe80::eed:f0a1:d03a:1028", new UInt32(25))); + thenResultingBuildAllMapContains("ipv6", "ignore-auto-dns", true); + thenResultingBuildAllMapContains("ipv6", "ignore-auto-routes", true); + thenResultingBuildAllMapNotContains("ipv6", "gateway"); + thenResultingBuildAllMapNotContains("ipv6", "dns"); + thenResultingBuildAllMapContains("connection", "id", "kura-eth0-connection"); + thenResultingBuildAllMapContains("connection", "interface-name", "eth0"); + thenResultingBuildAllMapContains("connection", "type", "802-3-ethernet"); + } + + @Test + public void buildSettingsShouldWorkWithExpectedInputsEthernetAndWanIp4AndIp6() { + givenMapWith("net.interface.eth0.config.dhcpClient4.enabled", false); + givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusEnabledWAN"); + givenMapWith("net.interface.eth0.config.ip4.address", "192.168.0.12"); + givenMapWith("net.interface.eth0.config.ip4.prefix", (short) 25); + givenMapWith("net.interface.eth0.config.ip4.dnsServers", "1.1.1.1"); + givenMapWith("net.interface.eth0.config.ip4.gateway", "192.168.0.1"); + givenMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusEnabledWAN"); + givenMapWith("net.interface.eth0.config.ip6.address.method", "netIPv6MethodManual"); + givenMapWith("net.interface.eth0.config.ip6.address", "fe80::eed:f0a1:d03a:1028"); + givenMapWith("net.interface.eth0.config.ip6.prefix", (short) 25); + givenMapWith("net.interface.eth0.config.ip6.dnsServers", "2001:4860:4860:0:0:0:0:8844"); + givenMapWith("net.interface.eth0.config.ip6.gateway", "fe80::eed:f0a1:d03a:1"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "eth0", "eth0", + NMDeviceType.NM_DEVICE_TYPE_ETHERNET); + + thenNoExceptionsHaveBeenThrown(); + thenResultingBuildAllMapContains("ipv4", "method", "manual"); + thenResultingBuildAllMapContains("ipv4", "address-data", buildAddressDataWith("192.168.0.12", new UInt32(25))); + thenResultingBuildAllMapContains("ipv4", "gateway", "192.168.0.1"); + thenResultingBuildAllMapContains("ipv4", "dns", + new Variant<>(Arrays.asList(new UInt32(16843009)), "au").getValue()); + thenResultingBuildAllMapContains("ipv4", "ignore-auto-dns", true); + thenResultingBuildAllMapNotContains("ipv4", "ignore-auto-routes"); + thenResultingBuildAllMapContains("ipv6", "method", "manual"); + thenResultingBuildAllMapContains("ipv6", "address-data", + buildAddressDataWith("fe80::eed:f0a1:d03a:1028", new UInt32(25))); + thenResultingBuildAllMapContains("ipv6", "gateway", "fe80::eed:f0a1:d03a:1"); + thenResultingBuildAllMapContains("ipv6", "dns", Arrays.asList(IP6_BYTE_ARRAY_ADDRESS)); + thenResultingBuildAllMapContains("ipv6", "ignore-auto-dns", true); + thenResultingBuildAllMapNotContains("ipv6", "ignore-auto-routes"); + thenResultingBuildAllMapContains("connection", "id", "kura-eth0-connection"); + thenResultingBuildAllMapContains("connection", "interface-name", "eth0"); + thenResultingBuildAllMapContains("connection", "type", "802-3-ethernet"); + } + + @Test + public void buildSettingsShouldWorkWithModemSettingsIp4AndIp6() { + givenMapWith("net.interface.1-1.1.config.dhcpClient4.enabled", true); + givenMapWith("net.interface.1-1.1.config.ip4.status", "netIPv4StatusEnabledWAN"); + givenMapWith("net.interface.1-1.1.config.ip6.status", "netIPv6StatusEnabledWAN"); + givenMapWith("net.interface.1-1.1.config.ip6.address.method", "netIPv6MethodAuto"); + givenMapWith("net.interface.1-1.1.config.apn", "mobile.test.com"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "1-1.1", "ttyACM0", + NMDeviceType.NM_DEVICE_TYPE_MODEM); + + thenNoExceptionsHaveBeenThrown(); + thenResultingBuildAllMapContains("ipv6", "method", "auto"); + thenResultingBuildAllMapContains("ipv4", "method", "auto"); + thenResultingBuildAllMapContains("connection", "id", "kura-ttyACM0-connection"); + thenResultingBuildAllMapContains("connection", "interface-name", "ttyACM0"); + thenResultingBuildAllMapContains("connection", "type", "gsm"); + thenResultingBuildAllMapContains("connection", "autoconnect-retries", 1); + thenResultingBuildAllMapContains("gsm", "apn", "mobile.test.com"); + } + + @Test + public void buildSettingsShouldThrowWithManualIp6DhcpDisableIp4AndNullIp() { + givenMapWith("net.interface.eth0.config.dhcpClient4.enabled", false); + givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusEnabledWAN"); + givenMapWith("net.interface.eth0.config.ip4.address", null); + givenMapWith("net.interface.eth0.config.ip4.prefix", (short) 25); + givenMapWith("net.interface.eth0.config.ip4.dnsServers", "1.1.1.1"); + givenMapWith("net.interface.eth0.config.ip4.gateway", "192.168.0.1"); + givenMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusEnabledWAN"); + givenMapWith("net.interface.eth0.config.ip6.address.method", "netIPv6MethodManual"); + givenMapWith("net.interface.eth0.config.ip6.address", null); + givenMapWith("net.interface.eth0.config.ip6.prefix", (short) 25); + givenMapWith("net.interface.eth0.config.ip6.dnsServers", "2001:4860:4860:0:0:0:0:8844"); + givenMapWith("net.interface.eth0.config.ip6.gateway", "fe80::eed:f0a1:d03a:1"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "eth0", "eth0", + NMDeviceType.NM_DEVICE_TYPE_ETHERNET); + + thenNoSuchElementExceptionThrown(); + } + + @Test + public void buildSettingsShouldThrowWithManualIp6DhcpDisableIp4AndNullPrefix() { + givenMapWith("net.interface.eth0.config.dhcpClient4.enabled", false); + givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusEnabledWAN"); + givenMapWith("net.interface.eth0.config.ip4.address", "192.168.0.12"); + givenMapWith("net.interface.eth0.config.ip4.prefix", null); + givenMapWith("net.interface.eth0.config.ip4.dnsServers", "1.1.1.1"); + givenMapWith("net.interface.eth0.config.ip4.gateway", "192.168.0.1"); + givenMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusEnabledWAN"); + givenMapWith("net.interface.eth0.config.ip6.address.method", "netIPv6MethodManual"); + givenMapWith("net.interface.eth0.config.ip6.address", "fe80::eed:f0a1:d03a:1028"); + givenMapWith("net.interface.eth0.config.ip6.prefix", null); + givenMapWith("net.interface.eth0.config.ip6.dnsServers", "2001:4860:4860:0:0:0:0:8844"); + givenMapWith("net.interface.eth0.config.ip6.gateway", "fe80::eed:f0a1:d03a:1"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "eth0", "eth0", + NMDeviceType.NM_DEVICE_TYPE_ETHERNET); + + thenNoSuchElementExceptionThrown(); + } + + @Test + public void buildSettingsShouldWorkWithManualIp6DhcpDisableIp4AndNullStatus() { + givenMapWith("net.interface.eth0.config.dhcpClient4.enabled", false); + givenMapWith("net.interface.eth0.config.ip4.status", null); + givenMapWith("net.interface.eth0.config.ip4.address", "192.168.0.12"); + givenMapWith("net.interface.eth0.config.ip4.prefix", (short) 25); + givenMapWith("net.interface.eth0.config.ip4.dnsServers", "1.1.1.1"); + givenMapWith("net.interface.eth0.config.ip4.gateway", "192.168.0.1"); + givenMapWith("net.interface.eth0.config.ip4.status", "netIPv6StatusDisabled"); + givenMapWith("net.interface.eth0.config.ip6.status", null); + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodManual"); + givenMapWith("net.interface.eth0.config.ip6.address", "fe80::eed:f0a1:d03a:1028"); + givenMapWith("net.interface.eth0.config.ip6.prefix", (short) 25); + givenMapWith("net.interface.eth0.config.ip6.dnsServers", "2001:4860:4860:0:0:0:0:8844"); + givenMapWith("net.interface.eth0.config.ip6.gateway", "fe80::eed:f0a1:d03a:1"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "eth0", "eth0", + NMDeviceType.NM_DEVICE_TYPE_ETHERNET); + + thenResultingBuildAllMapContains("ipv6", "method", "disabled"); + } + + @Test + public void buildSettingsShouldThrowWithManualIp6DhcpDisableIp4AndNullWifiSsid() { + givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); + givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusEnabledWAN"); + givenMapWith("net.interface.wlan0.config.ip4.address", "192.168.0.12"); + givenMapWith("net.interface.wlan0.config.ip4.prefix", (short) 25); + givenMapWith("net.interface.wlan0.config.ip4.dnsServers", "1.1.1.1"); + givenMapWith("net.interface.wlan0.config.ip4.gateway", "192.168.0.1"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledWAN"); + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodManual"); + givenMapWith("net.interface.wlan0.config.ip6.address", "fe80::eed:f0a1:d03a:1028"); + givenMapWith("net.interface.wlan0.config.ip6.prefix", (short) 25); + givenMapWith("net.interface.wlan0.config.ip6.dnsServers", "2001:4860:4860:0:0:0:0:8844"); + givenMapWith("net.interface.wlan0.config.ip6.gateway", "fe80::eed:f0a1:d03a:1"); + givenMapWith("net.interface.wlan0.config.wifi.mode", "INFRA"); + givenMapWith("net.interface.wlan0.config.wifi.infra.ssid", null); + givenMapWith("net.interface.wlan0.config.wifi.infra.radioMode", "RADIO_MODE_80211a"); + givenMapWith("net.interface.wlan0.config.wifi.infra.channel", "10"); + givenMapWith("net.interface.wlan0.config.wifi.infra.ignoreSSID", true); + givenMapWith("net.interface.wlan0.config.wifi.mode", "INFRA"); + givenMapWith("net.interface.wlan0.config.wifi.infra.passphrase", new Password("test")); + givenMapWith("net.interface.wlan0.config.wifi.infra.securityType", "SECURITY_WPA_WPA2"); + givenMapWith("net.interface.wlan0.config.wifi.infra.groupCiphers", "CCMP"); + givenMapWith("net.interface.wlan0.config.wifi.infra.pairwiseCiphers", "CCMP"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "wlan0", "wlan0", + NMDeviceType.NM_DEVICE_TYPE_WIFI); + + thenNoSuchElementExceptionThrown(); + } + + @Test + public void buildSettingsShouldThrowWithManualIp6DhcpDisableIp4AndNullWifiPassword() { + givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); + givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusEnabledWAN"); + givenMapWith("net.interface.wlan0.config.ip4.address", "192.168.0.12"); + givenMapWith("net.interface.wlan0.config.ip4.prefix", (short) 25); + givenMapWith("net.interface.wlan0.config.ip4.dnsServers", "1.1.1.1"); + givenMapWith("net.interface.wlan0.config.ip4.gateway", "192.168.0.1"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledWAN"); + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodManual"); + givenMapWith("net.interface.wlan0.config.ip6.address", "fe80::eed:f0a1:d03a:1028"); + givenMapWith("net.interface.wlan0.config.ip6.prefix", (short) 25); + givenMapWith("net.interface.wlan0.config.ip6.dnsServers", "2001:4860:4860:0:0:0:0:8844"); + givenMapWith("net.interface.wlan0.config.ip6.gateway", "fe80::eed:f0a1:d03a:1"); + givenMapWith("net.interface.wlan0.config.wifi.mode", "INFRA"); + givenMapWith("net.interface.wlan0.config.wifi.infra.ssid", "ssidtest"); + givenMapWith("net.interface.wlan0.config.wifi.infra.radioMode", null); + givenMapWith("net.interface.wlan0.config.wifi.infra.channel", "10"); + givenMapWith("net.interface.wlan0.config.wifi.infra.ignoreSSID", true); + givenMapWith("net.interface.wlan0.config.wifi.mode", "INFRA"); + givenMapWith("net.interface.wlan0.config.wifi.infra.passphrase", null); + givenMapWith("net.interface.wlan0.config.wifi.infra.securityType", "SECURITY_WPA_WPA2"); + givenMapWith("net.interface.wlan0.config.wifi.infra.groupCiphers", "CCMP"); + givenMapWith("net.interface.wlan0.config.wifi.infra.pairwiseCiphers", "CCMP"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "wlan0", "wlan0", + NMDeviceType.NM_DEVICE_TYPE_WIFI); + + thenNoSuchElementExceptionThrown(); + } + + @Test + public void buildSettingsShouldThrowWithManualIp6DhcpDisableIp4AndNullWifiSecurityType() { + givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); + givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusEnabledWAN"); + givenMapWith("net.interface.wlan0.config.ip4.address", "192.168.0.12"); + givenMapWith("net.interface.wlan0.config.ip4.prefix", (short) 25); + givenMapWith("net.interface.wlan0.config.ip4.dnsServers", "1.1.1.1"); + givenMapWith("net.interface.wlan0.config.ip4.gateway", "192.168.0.1"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledWAN"); + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodManual"); + givenMapWith("net.interface.wlan0.config.ip6.address", "fe80::eed:f0a1:d03a:1028"); + givenMapWith("net.interface.wlan0.config.ip6.prefix", (short) 25); + givenMapWith("net.interface.wlan0.config.ip6.dnsServers", "2001:4860:4860:0:0:0:0:8844"); + givenMapWith("net.interface.wlan0.config.ip6.gateway", "fe80::eed:f0a1:d03a:1"); + givenMapWith("net.interface.wlan0.config.wifi.mode", "INFRA"); + givenMapWith("net.interface.wlan0.config.wifi.infra.ssid", "ssidtest"); + givenMapWith("net.interface.wlan0.config.wifi.infra.radioMode", "RADIO_MODE_80211a"); + givenMapWith("net.interface.wlan0.config.wifi.infra.channel", "10"); + givenMapWith("net.interface.wlan0.config.wifi.infra.ignoreSSID", true); + givenMapWith("net.interface.wlan0.config.wifi.mode", "INFRA"); + givenMapWith("net.interface.wlan0.config.wifi.infra.passphrase", new Password("test")); + givenMapWith("net.interface.wlan0.config.wifi.infra.securityType", null); + givenMapWith("net.interface.wlan0.config.wifi.infra.groupCiphers", "CCMP"); + givenMapWith("net.interface.wlan0.config.wifi.infra.pairwiseCiphers", "CCMP"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "wlan0", "wlan0", + NMDeviceType.NM_DEVICE_TYPE_WIFI); + + thenNoSuchElementExceptionThrown(); + } + /* * Given */