From b13130ff56bb716802a92a8ff1edd541f080bb09 Mon Sep 17 00:00:00 2001 From: SimoneFiorani Date: Mon, 24 Jul 2023 17:15:44 +0200 Subject: [PATCH 01/11] feat(nm): Add first ipv6 configuration --- .../eclipse/kura/nm/KuraIP6ConfigPrivacy.java | 50 ++++++++++ .../nm/KuraIpv6AddressGenerationMethod.java | 49 ++++++++++ .../org/eclipse/kura/nm/NMDbusConnector.java | 4 +- .../nm/configuration/NMSettingsConverter.java | 94 ++++++++++++++++++- 4 files changed, 193 insertions(+), 4 deletions(-) create mode 100644 kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIP6ConfigPrivacy.java create mode 100644 kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIpv6AddressGenerationMethod.java diff --git a/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIP6ConfigPrivacy.java b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIP6ConfigPrivacy.java new file mode 100644 index 00000000000..553beca7589 --- /dev/null +++ b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIP6ConfigPrivacy.java @@ -0,0 +1,50 @@ +package org.eclipse.kura.nm; + +import java.util.Arrays; +import java.util.List; + +public enum KuraIP6ConfigPrivacy { + + UNKNOWN, + DISABLED, + ENABLED_PUBLIC_ADD, + ENABLED_TEMP_ADD; + + private static final List ENABLED_STATUS = Arrays.asList(KuraIP6ConfigPrivacy.UNKNOWN, + KuraIP6ConfigPrivacy.DISABLED, KuraIP6ConfigPrivacy.ENABLED_PUBLIC_ADD, + KuraIP6ConfigPrivacy.ENABLED_TEMP_ADD); + + public static Boolean isEnabled(KuraIP6ConfigPrivacy status) { + return ENABLED_STATUS.contains(status); + } + + public static KuraIP6ConfigPrivacy fromString(String status) { + switch (status) { + case "netIPv6PrivacyUnknown": + return KuraIP6ConfigPrivacy.UNKNOWN; + case "netIPv6PrivacyDisabled": + return KuraIP6ConfigPrivacy.DISABLED; + case "netIPv6PrivacyEnabledPubAdd": + return KuraIP6ConfigPrivacy.ENABLED_PUBLIC_ADD; + case "netIPv6PrivacyEnabledTempAdd": + return KuraIP6ConfigPrivacy.ENABLED_TEMP_ADD; + default: + return KuraIP6ConfigPrivacy.UNKNOWN; + } + } + + public static Integer ip6PrivacyCode(KuraIP6ConfigPrivacy privacyValue) { + switch (privacyValue) { + case UNKNOWN: + return -1; + case DISABLED: + return 0; + case ENABLED_PUBLIC_ADD: + return 1; + case ENABLED_TEMP_ADD: + return 2; + default: + return -1; + } + } +} diff --git a/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIpv6AddressGenerationMethod.java b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIpv6AddressGenerationMethod.java new file mode 100644 index 00000000000..bea17e673c2 --- /dev/null +++ b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIpv6AddressGenerationMethod.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * 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 java.util.Arrays; +import java.util.List; + +public enum KuraIpv6AddressGenerationMethod { + + AUTO, + DHCP, + MANUAL, + UNKNOWN; + + private static final List ENABLED_STATUS = Arrays.asList( + KuraIpv6AddressGenerationMethod.AUTO, KuraIpv6AddressGenerationMethod.DHCP, + KuraIpv6AddressGenerationMethod.MANUAL); + + public static Boolean isEnabled(KuraIpv6AddressGenerationMethod status) { + return ENABLED_STATUS.contains(status); + } + + public static KuraIpv6AddressGenerationMethod fromString(String status) { + switch (status) { + case "netIPv6MethodAuto": + return KuraIpv6AddressGenerationMethod.AUTO; + case "netIPv6MethodDhcp": + return KuraIpv6AddressGenerationMethod.DHCP; + case "netIPv6MethodManual": + return KuraIpv6AddressGenerationMethod.MANUAL; + default: + return KuraIpv6AddressGenerationMethod.UNKNOWN; + + } + + } + +} \ No newline at end of file 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..8f5ba0eec6f 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,8 @@ 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; + KuraIpStatus ip6Status = KuraIpStatus + .fromString(properties.get(String.class, "net.interface.%s.config.ip6.status", deviceId)); 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 06ef1442c0b..a10c41c867b 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,8 +23,10 @@ import java.util.Optional; import org.eclipse.kura.configuration.Password; +import org.eclipse.kura.nm.KuraIP6ConfigPrivacy; import org.eclipse.kura.nm.KuraIpStatus; import org.eclipse.kura.nm.KuraWifiSecurityType; +import org.eclipse.kura.nm.KuraIpv6AddressGenerationMethod; import org.eclipse.kura.nm.NetworkProperties; import org.eclipse.kura.nm.enums.NMDeviceType; import org.freedesktop.dbus.types.UInt32; @@ -149,8 +151,75 @@ public static Map> buildIpv4Settings(NetworkProperties props, public static Map> buildIpv6Settings(NetworkProperties props, String deviceId) { Map> settings = new HashMap<>(); - // Disabled for now - settings.put(NM_SETTINGS_IPV6_METHOD, new Variant<>("disabled")); + KuraIpStatus ip6Status = KuraIpStatus + .fromString(props.get(String.class, "net.interface.%s.config.ip6.status", deviceId)); + + Boolean ipv6AddressGenerationMode = props.get(Boolean.class, "net.interface.%s.config.ip6.addr.gen.mode", + deviceId); + // 1 = STABLE_PRIVACY 0 = EUI64 + settings.put("addr-gen-mode", + new Variant<>(Boolean.TRUE.equals((ipv6AddressGenerationMode)) ? (int) 1 : (int) 0)); + + KuraIP6ConfigPrivacy ip6Privacy = KuraIP6ConfigPrivacy + .fromString(props.get(String.class, "net.interface.%s.config.ip6.privacy", deviceId)); + settings.put("ip6-privacy", new Variant<>(KuraIP6ConfigPrivacy.ip6PrivacyCode(ip6Privacy))); + + KuraIpv6AddressGenerationMethod ip6GenMethod = KuraIpv6AddressGenerationMethod + .fromString(props.get(String.class, "net.interface.%s.config.ip6.address.generation", deviceId)); + + if (ip6GenMethod.equals(KuraIpv6AddressGenerationMethod.AUTO)) { + + settings.put(NM_SETTINGS_IPV6_METHOD, new Variant<>("auto")); + + } else if (ip6GenMethod.equals(KuraIpv6AddressGenerationMethod.DHCP)) { + + settings.put(NM_SETTINGS_IPV6_METHOD, new Variant<>("dhcp")); + + } else if (ip6GenMethod.equals(KuraIpv6AddressGenerationMethod.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\"", ip6GenMethod)); + } + + if (ip6Status.equals(KuraIpStatus.ENABLEDLAN)) { + settings.put("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); + if (dnsServers.isPresent()) { + settings.put("dns", new Variant<>(convertIp6(dnsServers.get()), "au")); + settings.put("ignore-auto-dns", new Variant<>(true)); + } + + Optional wanPriority = props.getOpt(Integer.class, "net.interface.%s.config.ip6.wan.priority", + deviceId); + if (wanPriority.isPresent()) { + Long supportedByNM = wanPriority.get().longValue(); + settings.put("route-metric", new Variant<>(supportedByNM)); + } + } else { + logger.warn("Unexpected ip status received: \"{}\". Ignoring", ip6Status); + } return settings; } @@ -366,6 +435,27 @@ 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 = 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); + + List returnList = new ArrayList<>(); + returnList.add(address.getAddress()); // sistemar ordine + + return returnList; + } + private static String wifiModeConvert(String kuraMode) { switch (kuraMode) { case "INFRA": From 10d24626f7b17e38b24ecc70b13105b385c0e09e Mon Sep 17 00:00:00 2001 From: SimoneFiorani Date: Tue, 25 Jul 2023 13:02:08 +0200 Subject: [PATCH 02/11] feat(nm): added 'NMSettingIP6ConfigPrivacy' class and updated 'convertIp6' method Signed-off-by: SimoneFiorani --- .../eclipse/kura/nm/KuraIP6ConfigPrivacy.java | 14 ++++---- .../nm/configuration/NMSettingsConverter.java | 23 +++++++----- .../nm/enums/NMSettingIP6ConfigPrivacy.java | 35 +++++++++++++++++++ 3 files changed, 57 insertions(+), 15 deletions(-) create mode 100644 kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/enums/NMSettingIP6ConfigPrivacy.java diff --git a/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIP6ConfigPrivacy.java b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIP6ConfigPrivacy.java index 553beca7589..55f1d4e12eb 100644 --- a/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIP6ConfigPrivacy.java +++ b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIP6ConfigPrivacy.java @@ -3,6 +3,8 @@ import java.util.Arrays; import java.util.List; +import org.eclipse.kura.nm.enums.NMSettingIP6ConfigPrivacy; + public enum KuraIP6ConfigPrivacy { UNKNOWN, @@ -33,18 +35,18 @@ public static KuraIP6ConfigPrivacy fromString(String status) { } } - public static Integer ip6PrivacyCode(KuraIP6ConfigPrivacy privacyValue) { + public static NMSettingIP6ConfigPrivacy toNMSettingIP6ConfigPrivacy(KuraIP6ConfigPrivacy privacyValue) { switch (privacyValue) { case UNKNOWN: - return -1; + return NMSettingIP6ConfigPrivacy.NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN; case DISABLED: - return 0; + return NMSettingIP6ConfigPrivacy.NM_SETTING_IP6_CONFIG_PRIVACY_DISABLED; case ENABLED_PUBLIC_ADD: - return 1; + return NMSettingIP6ConfigPrivacy.NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR; case ENABLED_TEMP_ADD: - return 2; + return NMSettingIP6ConfigPrivacy.NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR; default: - return -1; + return NMSettingIP6ConfigPrivacy.NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN; } } } 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 a10c41c867b..c7dd8181a81 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 @@ -162,7 +162,8 @@ public static Map> buildIpv6Settings(NetworkProperties props, KuraIP6ConfigPrivacy ip6Privacy = KuraIP6ConfigPrivacy .fromString(props.get(String.class, "net.interface.%s.config.ip6.privacy", deviceId)); - settings.put("ip6-privacy", new Variant<>(KuraIP6ConfigPrivacy.ip6PrivacyCode(ip6Privacy))); + settings.put("ip6-privacy", + new Variant<>(KuraIP6ConfigPrivacy.toNMSettingIP6ConfigPrivacy(ip6Privacy).toInt32())); KuraIpv6AddressGenerationMethod ip6GenMethod = KuraIpv6AddressGenerationMethod .fromString(props.get(String.class, "net.interface.%s.config.ip6.address.generation", deviceId)); @@ -207,7 +208,7 @@ public static Map> buildIpv6Settings(NetworkProperties props, Optional> dnsServers = props.getOptStringList("net.interface.%s.config.ip6.dnsServers", deviceId); if (dnsServers.isPresent()) { - settings.put("dns", new Variant<>(convertIp6(dnsServers.get()), "au")); + settings.put("dns", new Variant<>(convertIp6(dnsServers.get()), "aay")); settings.put("ignore-auto-dns", new Variant<>(true)); } @@ -435,11 +436,11 @@ private static UInt32 convertIp4(String ipAddrString) throws UnknownHostExceptio return new UInt32(result); } - private static List convertIp6(List ipAddrList) { - List uint32Addresses = new ArrayList<>(); + private static List> convertIp6(List ipAddrList) { + List> uint32Addresses = new ArrayList<>(); for (String address : ipAddrList) { try { - uint32Addresses = convertIp6(address); + uint32Addresses.add(convertIp6(address)); } catch (UnknownHostException e) { logger.warn("Cannot convert ip address \"{}\" because: ", address, e); } @@ -447,13 +448,17 @@ private static List convertIp6(List ipAddrList) { return uint32Addresses; } - private static List convertIp6(String ipAddrString) throws UnknownHostException { + private static List convertIp6(String ipAddrString) throws UnknownHostException { InetAddress address = InetAddress.getByName(ipAddrString); - List returnList = new ArrayList<>(); - returnList.add(address.getAddress()); // sistemar ordine + byte[] dnsByteArray = address.getAddress(); - return returnList; + List dnsAddress = new ArrayList<>(); + for (int i = 0; i < dnsByteArray.length; i++) { + dnsAddress.add(dnsByteArray[i]); + } + + return dnsAddress; } private static String wifiModeConvert(String kuraMode) { 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..c370e022cc3 --- /dev/null +++ b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/enums/NMSettingIP6ConfigPrivacy.java @@ -0,0 +1,35 @@ +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; + } + } + +} From a052e8f21c773c080dd627312092b8f8b9ffe9fd Mon Sep 17 00:00:00 2001 From: SimoneFiorani Date: Tue, 25 Jul 2023 14:33:16 +0200 Subject: [PATCH 03/11] Added classes for IP6 Address Generation Mode setting Signed-off-by: SimoneFiorani --- .../kura/nm/KuraIP6ConfigAddGenMode.java | 45 +++++++++++++++++++ ...erationMethod.java => KuraIpv6Method.java} | 19 ++++---- .../nm/configuration/NMSettingsConverter.java | 20 ++++----- .../enums/NMSettingIP6ConfigAddrGenMode.java | 35 +++++++++++++++ 4 files changed, 99 insertions(+), 20 deletions(-) create mode 100644 kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIP6ConfigAddGenMode.java rename kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/{KuraIpv6AddressGenerationMethod.java => KuraIpv6Method.java} (55%) create mode 100644 kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/enums/NMSettingIP6ConfigAddrGenMode.java diff --git a/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIP6ConfigAddGenMode.java b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIP6ConfigAddGenMode.java new file mode 100644 index 00000000000..56357f6a3cb --- /dev/null +++ b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIP6ConfigAddGenMode.java @@ -0,0 +1,45 @@ +package org.eclipse.kura.nm; + +import java.util.Arrays; +import java.util.List; + +import org.eclipse.kura.nm.enums.NMSettingIP6ConfigAddrGenMode; +import org.eclipse.kura.nm.enums.NMSettingIP6ConfigPrivacy; + +public enum KuraIP6ConfigAddGenMode { + + UNKNOWN, + EUI64, + STABLE_PRIVACY; + + private static final List ADDRESS_GEN_MODE = Arrays.asList(KuraIP6ConfigAddGenMode.UNKNOWN, + KuraIP6ConfigAddGenMode.EUI64, KuraIP6ConfigAddGenMode.STABLE_PRIVACY); + + public static Boolean isEnabled(KuraIP6ConfigAddGenMode status) { + return ADDRESS_GEN_MODE.contains(status); + } + + // UNKNOWN value is not present in NM, it will be used to track unwanted configurations + public static KuraIP6ConfigAddGenMode fromString(String status) { + switch (status) { + case "netIPv6AddressGenModeEUI64": + return KuraIP6ConfigAddGenMode.EUI64; + case "netIPv6AddressGenModeStablePrivacy": + return KuraIP6ConfigAddGenMode.STABLE_PRIVACY; + default: + return KuraIP6ConfigAddGenMode.UNKNOWN; + } + } + + // Default will throw an IllegalArgumentException + public static NMSettingIP6ConfigAddrGenMode toNMSettingIP6ConfigAddrGenMode(KuraIP6ConfigAddGenMode 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: + return NMSettingIP6ConfigAddrGenMode.NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_DEFAULT; + } + } +} diff --git a/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIpv6AddressGenerationMethod.java b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIpv6Method.java similarity index 55% rename from kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIpv6AddressGenerationMethod.java rename to kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIpv6Method.java index bea17e673c2..64e351835ba 100644 --- a/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIpv6AddressGenerationMethod.java +++ b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIpv6Method.java @@ -16,31 +16,30 @@ import java.util.Arrays; import java.util.List; -public enum KuraIpv6AddressGenerationMethod { +public enum KuraIpv6Method { AUTO, DHCP, MANUAL, UNKNOWN; - private static final List ENABLED_STATUS = Arrays.asList( - KuraIpv6AddressGenerationMethod.AUTO, KuraIpv6AddressGenerationMethod.DHCP, - KuraIpv6AddressGenerationMethod.MANUAL); + private static final List ENABLED_STATUS = Arrays.asList(KuraIpv6Method.AUTO, KuraIpv6Method.DHCP, + KuraIpv6Method.MANUAL); - public static Boolean isEnabled(KuraIpv6AddressGenerationMethod status) { + public static Boolean isEnabled(KuraIpv6Method status) { return ENABLED_STATUS.contains(status); } - public static KuraIpv6AddressGenerationMethod fromString(String status) { + public static KuraIpv6Method fromString(String status) { switch (status) { case "netIPv6MethodAuto": - return KuraIpv6AddressGenerationMethod.AUTO; + return KuraIpv6Method.AUTO; case "netIPv6MethodDhcp": - return KuraIpv6AddressGenerationMethod.DHCP; + return KuraIpv6Method.DHCP; case "netIPv6MethodManual": - return KuraIpv6AddressGenerationMethod.MANUAL; + return KuraIpv6Method.MANUAL; default: - return KuraIpv6AddressGenerationMethod.UNKNOWN; + return KuraIpv6Method.UNKNOWN; } 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 c7dd8181a81..6a9e1cd2c2d 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,10 +23,11 @@ import java.util.Optional; import org.eclipse.kura.configuration.Password; +import org.eclipse.kura.nm.KuraIP6ConfigAddGenMode; import org.eclipse.kura.nm.KuraIP6ConfigPrivacy; import org.eclipse.kura.nm.KuraIpStatus; +import org.eclipse.kura.nm.KuraIpv6Method; import org.eclipse.kura.nm.KuraWifiSecurityType; -import org.eclipse.kura.nm.KuraIpv6AddressGenerationMethod; import org.eclipse.kura.nm.NetworkProperties; import org.eclipse.kura.nm.enums.NMDeviceType; import org.freedesktop.dbus.types.UInt32; @@ -154,29 +155,28 @@ public static Map> buildIpv6Settings(NetworkProperties props, KuraIpStatus ip6Status = KuraIpStatus .fromString(props.get(String.class, "net.interface.%s.config.ip6.status", deviceId)); - Boolean ipv6AddressGenerationMode = props.get(Boolean.class, "net.interface.%s.config.ip6.addr.gen.mode", - deviceId); - // 1 = STABLE_PRIVACY 0 = EUI64 - settings.put("addr-gen-mode", - new Variant<>(Boolean.TRUE.equals((ipv6AddressGenerationMode)) ? (int) 1 : (int) 0)); + KuraIP6ConfigAddGenMode ipv6AddressGenerationMode = KuraIP6ConfigAddGenMode + .fromString(props.get(String.class, "net.interface.%s.config.ip6.addr.gen.mode", deviceId)); + settings.put("addr-gen-mode", new Variant<>( + KuraIP6ConfigAddGenMode.toNMSettingIP6ConfigAddrGenMode(ipv6AddressGenerationMode).toInt32())); KuraIP6ConfigPrivacy ip6Privacy = KuraIP6ConfigPrivacy .fromString(props.get(String.class, "net.interface.%s.config.ip6.privacy", deviceId)); settings.put("ip6-privacy", new Variant<>(KuraIP6ConfigPrivacy.toNMSettingIP6ConfigPrivacy(ip6Privacy).toInt32())); - KuraIpv6AddressGenerationMethod ip6GenMethod = KuraIpv6AddressGenerationMethod + KuraIpv6Method ip6GenMethod = KuraIpv6Method .fromString(props.get(String.class, "net.interface.%s.config.ip6.address.generation", deviceId)); - if (ip6GenMethod.equals(KuraIpv6AddressGenerationMethod.AUTO)) { + if (ip6GenMethod.equals(KuraIpv6Method.AUTO)) { settings.put(NM_SETTINGS_IPV6_METHOD, new Variant<>("auto")); - } else if (ip6GenMethod.equals(KuraIpv6AddressGenerationMethod.DHCP)) { + } else if (ip6GenMethod.equals(KuraIpv6Method.DHCP)) { settings.put(NM_SETTINGS_IPV6_METHOD, new Variant<>("dhcp")); - } else if (ip6GenMethod.equals(KuraIpv6AddressGenerationMethod.MANUAL)) { + } else if (ip6GenMethod.equals(KuraIpv6Method.MANUAL)) { settings.put(NM_SETTINGS_IPV6_METHOD, new Variant<>("manual")); 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..39b8bb18317 --- /dev/null +++ b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/enums/NMSettingIP6ConfigAddrGenMode.java @@ -0,0 +1,35 @@ +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; + } + } + +} From b6757ead97573399f4eca52b6e70752699374a40 Mon Sep 17 00:00:00 2001 From: SimoneFiorani Date: Tue, 25 Jul 2023 16:55:20 +0200 Subject: [PATCH 04/11] Classes refactor, added ipv6 settings unit tests Signed-off-by: SimoneFiorani --- .../kura/nm/KuraIP6ConfigAddGenMode.java | 45 ------ .../kura/nm/KuraIp6AddressGenerationMode.java | 44 ++++++ ...d.java => KuraIp6ConfigurationMethod.java} | 18 +-- ...ConfigPrivacy.java => KuraIp6Privacy.java} | 23 ++- .../nm/configuration/NMSettingsConverter.java | 52 ++++--- .../eclipse/kura/nm/NMDbusConnectorTest.java | 7 + .../NMSettingsConverterTest.java | 146 +++++++++++++++++- 7 files changed, 249 insertions(+), 86 deletions(-) delete mode 100644 kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIP6ConfigAddGenMode.java create mode 100644 kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIp6AddressGenerationMode.java rename kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/{KuraIpv6Method.java => KuraIp6ConfigurationMethod.java} (58%) rename kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/{KuraIP6ConfigPrivacy.java => KuraIp6Privacy.java} (61%) diff --git a/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIP6ConfigAddGenMode.java b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIP6ConfigAddGenMode.java deleted file mode 100644 index 56357f6a3cb..00000000000 --- a/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIP6ConfigAddGenMode.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.eclipse.kura.nm; - -import java.util.Arrays; -import java.util.List; - -import org.eclipse.kura.nm.enums.NMSettingIP6ConfigAddrGenMode; -import org.eclipse.kura.nm.enums.NMSettingIP6ConfigPrivacy; - -public enum KuraIP6ConfigAddGenMode { - - UNKNOWN, - EUI64, - STABLE_PRIVACY; - - private static final List ADDRESS_GEN_MODE = Arrays.asList(KuraIP6ConfigAddGenMode.UNKNOWN, - KuraIP6ConfigAddGenMode.EUI64, KuraIP6ConfigAddGenMode.STABLE_PRIVACY); - - public static Boolean isEnabled(KuraIP6ConfigAddGenMode status) { - return ADDRESS_GEN_MODE.contains(status); - } - - // UNKNOWN value is not present in NM, it will be used to track unwanted configurations - public static KuraIP6ConfigAddGenMode fromString(String status) { - switch (status) { - case "netIPv6AddressGenModeEUI64": - return KuraIP6ConfigAddGenMode.EUI64; - case "netIPv6AddressGenModeStablePrivacy": - return KuraIP6ConfigAddGenMode.STABLE_PRIVACY; - default: - return KuraIP6ConfigAddGenMode.UNKNOWN; - } - } - - // Default will throw an IllegalArgumentException - public static NMSettingIP6ConfigAddrGenMode toNMSettingIP6ConfigAddrGenMode(KuraIP6ConfigAddGenMode 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: - return NMSettingIP6ConfigAddrGenMode.NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_DEFAULT; - } - } -} 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..df7b12373c1 --- /dev/null +++ b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIp6AddressGenerationMode.java @@ -0,0 +1,44 @@ +package org.eclipse.kura.nm; + +import java.util.Arrays; +import java.util.List; + +import org.eclipse.kura.nm.enums.NMSettingIP6ConfigAddrGenMode; + +public enum KuraIp6AddressGenerationMode { + + EUI64, + STABLE_PRIVACY; + + private static final List ADDRESS_GEN_MODE = Arrays + .asList(KuraIp6AddressGenerationMode.EUI64, KuraIp6AddressGenerationMode.STABLE_PRIVACY); + + public static Boolean isEnabled(KuraIp6AddressGenerationMode status) { + return ADDRESS_GEN_MODE.contains(status); + } + + 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/KuraIpv6Method.java b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIp6ConfigurationMethod.java similarity index 58% rename from kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIpv6Method.java rename to kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIp6ConfigurationMethod.java index 64e351835ba..b5cec7c2dff 100644 --- a/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIpv6Method.java +++ b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIp6ConfigurationMethod.java @@ -16,30 +16,30 @@ import java.util.Arrays; import java.util.List; -public enum KuraIpv6Method { +public enum KuraIp6ConfigurationMethod { AUTO, DHCP, MANUAL, UNKNOWN; - private static final List ENABLED_STATUS = Arrays.asList(KuraIpv6Method.AUTO, KuraIpv6Method.DHCP, - KuraIpv6Method.MANUAL); + private static final List ENABLED_STATUS = Arrays.asList( + KuraIp6ConfigurationMethod.AUTO, KuraIp6ConfigurationMethod.DHCP, KuraIp6ConfigurationMethod.MANUAL); - public static Boolean isEnabled(KuraIpv6Method status) { + public static Boolean isEnabled(KuraIp6ConfigurationMethod status) { return ENABLED_STATUS.contains(status); } - public static KuraIpv6Method fromString(String status) { + public static KuraIp6ConfigurationMethod fromString(String status) { switch (status) { case "netIPv6MethodAuto": - return KuraIpv6Method.AUTO; + return KuraIp6ConfigurationMethod.AUTO; case "netIPv6MethodDhcp": - return KuraIpv6Method.DHCP; + return KuraIp6ConfigurationMethod.DHCP; case "netIPv6MethodManual": - return KuraIpv6Method.MANUAL; + return KuraIp6ConfigurationMethod.MANUAL; default: - return KuraIpv6Method.UNKNOWN; + return KuraIp6ConfigurationMethod.UNKNOWN; } diff --git a/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIP6ConfigPrivacy.java b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIp6Privacy.java similarity index 61% rename from kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIP6ConfigPrivacy.java rename to kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIp6Privacy.java index 55f1d4e12eb..1221534b442 100644 --- a/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIP6ConfigPrivacy.java +++ b/kura/org.eclipse.kura.nm/src/main/java/org/eclipse/kura/nm/KuraIp6Privacy.java @@ -5,37 +5,36 @@ import org.eclipse.kura.nm.enums.NMSettingIP6ConfigPrivacy; -public enum KuraIP6ConfigPrivacy { +public enum KuraIp6Privacy { UNKNOWN, DISABLED, ENABLED_PUBLIC_ADD, ENABLED_TEMP_ADD; - private static final List ENABLED_STATUS = Arrays.asList(KuraIP6ConfigPrivacy.UNKNOWN, - KuraIP6ConfigPrivacy.DISABLED, KuraIP6ConfigPrivacy.ENABLED_PUBLIC_ADD, - KuraIP6ConfigPrivacy.ENABLED_TEMP_ADD); + private static final List ENABLED_STATUS = Arrays.asList(KuraIp6Privacy.UNKNOWN, + KuraIp6Privacy.DISABLED, KuraIp6Privacy.ENABLED_PUBLIC_ADD, KuraIp6Privacy.ENABLED_TEMP_ADD); - public static Boolean isEnabled(KuraIP6ConfigPrivacy status) { + public static Boolean isEnabled(KuraIp6Privacy status) { return ENABLED_STATUS.contains(status); } - public static KuraIP6ConfigPrivacy fromString(String status) { + public static KuraIp6Privacy fromString(String status) { switch (status) { case "netIPv6PrivacyUnknown": - return KuraIP6ConfigPrivacy.UNKNOWN; + return KuraIp6Privacy.UNKNOWN; case "netIPv6PrivacyDisabled": - return KuraIP6ConfigPrivacy.DISABLED; + return KuraIp6Privacy.DISABLED; case "netIPv6PrivacyEnabledPubAdd": - return KuraIP6ConfigPrivacy.ENABLED_PUBLIC_ADD; + return KuraIp6Privacy.ENABLED_PUBLIC_ADD; case "netIPv6PrivacyEnabledTempAdd": - return KuraIP6ConfigPrivacy.ENABLED_TEMP_ADD; + return KuraIp6Privacy.ENABLED_TEMP_ADD; default: - return KuraIP6ConfigPrivacy.UNKNOWN; + return KuraIp6Privacy.UNKNOWN; } } - public static NMSettingIP6ConfigPrivacy toNMSettingIP6ConfigPrivacy(KuraIP6ConfigPrivacy privacyValue) { + public static NMSettingIP6ConfigPrivacy toNMSettingIP6ConfigPrivacy(KuraIp6Privacy privacyValue) { switch (privacyValue) { case UNKNOWN: return NMSettingIP6ConfigPrivacy.NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN; 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 6a9e1cd2c2d..9613ff483a2 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,10 +23,10 @@ import java.util.Optional; import org.eclipse.kura.configuration.Password; -import org.eclipse.kura.nm.KuraIP6ConfigAddGenMode; -import org.eclipse.kura.nm.KuraIP6ConfigPrivacy; +import org.eclipse.kura.nm.KuraIp6AddressGenerationMode; +import org.eclipse.kura.nm.KuraIp6Privacy; import org.eclipse.kura.nm.KuraIpStatus; -import org.eclipse.kura.nm.KuraIpv6Method; +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; @@ -150,33 +150,33 @@ public static Map> buildIpv4Settings(NetworkProperties props, } public static Map> buildIpv6Settings(NetworkProperties props, String deviceId) { - Map> settings = new HashMap<>(); KuraIpStatus ip6Status = KuraIpStatus .fromString(props.get(String.class, "net.interface.%s.config.ip6.status", deviceId)); - KuraIP6ConfigAddGenMode ipv6AddressGenerationMode = KuraIP6ConfigAddGenMode - .fromString(props.get(String.class, "net.interface.%s.config.ip6.addr.gen.mode", deviceId)); - settings.put("addr-gen-mode", new Variant<>( - KuraIP6ConfigAddGenMode.toNMSettingIP6ConfigAddrGenMode(ipv6AddressGenerationMode).toInt32())); + if (ip6Status == KuraIpStatus.UNMANAGED) { + throw new IllegalArgumentException("IPv6 status is not supported: " + ip6Status + + ". Build settings should be called only for managed interfaces."); + } - KuraIP6ConfigPrivacy ip6Privacy = KuraIP6ConfigPrivacy - .fromString(props.get(String.class, "net.interface.%s.config.ip6.privacy", deviceId)); - settings.put("ip6-privacy", - new Variant<>(KuraIP6ConfigPrivacy.toNMSettingIP6ConfigPrivacy(ip6Privacy).toInt32())); + Map> settings = new HashMap<>(); + if (ip6Status == KuraIpStatus.DISABLED) { + settings.put(NM_SETTINGS_IPV4_METHOD, new Variant<>("disabled")); + return settings; + } - KuraIpv6Method ip6GenMethod = KuraIpv6Method - .fromString(props.get(String.class, "net.interface.%s.config.ip6.address.generation", deviceId)); + KuraIp6ConfigurationMethod ip6ConfigMethod = KuraIp6ConfigurationMethod + .fromString(props.get(String.class, "net.interface.%s.config.ip6.address.method", deviceId)); - if (ip6GenMethod.equals(KuraIpv6Method.AUTO)) { + if (ip6ConfigMethod.equals(KuraIp6ConfigurationMethod.AUTO)) { settings.put(NM_SETTINGS_IPV6_METHOD, new Variant<>("auto")); - } else if (ip6GenMethod.equals(KuraIpv6Method.DHCP)) { + } else if (ip6ConfigMethod.equals(KuraIp6ConfigurationMethod.DHCP)) { settings.put(NM_SETTINGS_IPV6_METHOD, new Variant<>("dhcp")); - } else if (ip6GenMethod.equals(KuraIpv6Method.MANUAL)) { + } else if (ip6ConfigMethod.equals(KuraIp6ConfigurationMethod.MANUAL)) { settings.put(NM_SETTINGS_IPV6_METHOD, new Variant<>("manual")); @@ -197,7 +197,7 @@ public static Map> buildIpv6Settings(NetworkProperties props, } else { throw new IllegalArgumentException( - String.format("Unsupported IPv6 address generation mode: \"%s\"", ip6GenMethod)); + String.format("Unsupported IPv6 address generation mode: \"%s\"", ip6ConfigMethod)); } if (ip6Status.equals(KuraIpStatus.ENABLEDLAN)) { @@ -222,6 +222,22 @@ public static Map> buildIpv6Settings(NetworkProperties props, logger.warn("Unexpected ip status received: \"{}\". Ignoring", ip6Status); } + Optional addressGenerationMode = props.getOpt(String.class, "net.interface.%s.config.ip6.addr.gen.mode", + deviceId); + if (addressGenerationMode.isPresent()) { + 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); + if (privacy.isPresent()) { + KuraIp6Privacy ip6Privacy = KuraIp6Privacy.fromString(privacy.get()); + settings.put("ip6-privacy", + new Variant<>(KuraIp6Privacy.toNMSettingIP6ConfigPrivacy(ip6Privacy).toInt32())); + } + return settings; } diff --git a/kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/NMDbusConnectorTest.java b/kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/NMDbusConnectorTest.java index 8d45152cd0d..536f4502ea8 100644 --- a/kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/NMDbusConnectorTest.java +++ b/kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/NMDbusConnectorTest.java @@ -404,6 +404,7 @@ public void applyShouldWorkWithEnabledEthernet() throws DBusException, IOExcepti givenMockedDeviceList(); givenNetworkConfigMapWith("net.interfaces", "eth0"); + givenNetworkConfigMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusDisabled"); givenNetworkConfigMapWith("net.interface.eth0.config.dhcpClient4.enabled", false); givenNetworkConfigMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusEnabledWAN"); givenNetworkConfigMapWith("net.interface.eth0.config.ip4.address", "192.168.0.12"); @@ -426,6 +427,7 @@ public void applyShouldWorkWithEnabledEthernetWithoutInitialConnection() throws givenMockToPrepNetworkManagerToAllowDeviceToCreateNewConnection(); givenNetworkConfigMapWith("net.interfaces", "eth0"); + givenNetworkConfigMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusDisabled"); givenNetworkConfigMapWith("net.interface.eth0.config.dhcpClient4.enabled", false); givenNetworkConfigMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusEnabledWAN"); givenNetworkConfigMapWith("net.interface.eth0.config.ip4.address", "192.168.0.12"); @@ -532,6 +534,7 @@ public void applyShouldWorkWithEnabledModem() throws DBusException, IOException givenMockedDeviceList(); givenNetworkConfigMapWith("net.interfaces", "1-5,"); + givenNetworkConfigMapWith("net.interface.1-5.config.ip6.status", "netIPv6StatusDisabled"); givenNetworkConfigMapWith("net.interface.1-5.config.ip4.status", "netIPv4StatusEnabledWAN"); givenNetworkConfigMapWith("net.interface.1-5.config.dhcpClient4.enabled", true); givenNetworkConfigMapWith("net.interface.1-5.config.apn", "myAwesomeAPN"); @@ -554,6 +557,7 @@ public void applyShouldWorkWithModemWithEnabledGPS() throws DBusException, IOExc givenMockedDeviceList(); givenNetworkConfigMapWith("net.interfaces", "1-5,"); + givenNetworkConfigMapWith("net.interface.1-5.config.ip6.status", "netIPv6StatusDisabled"); givenNetworkConfigMapWith("net.interface.1-5.config.ip4.status", "netIPv4StatusEnabledWAN"); givenNetworkConfigMapWith("net.interface.1-5.config.dhcpClient4.enabled", true); givenNetworkConfigMapWith("net.interface.1-5.config.apn", "myAwesomeAPN"); @@ -576,6 +580,7 @@ public void applyShouldDisableGPSWithMissingGPSConfiguration() throws DBusExcept givenMockedDeviceList(); givenNetworkConfigMapWith("net.interfaces", "1-5,"); + givenNetworkConfigMapWith("net.interface.1-5.config.ip6.status", "netIPv6StatusDisabled"); givenNetworkConfigMapWith("net.interface.1-5.config.ip4.status", "netIPv4StatusEnabledWAN"); givenNetworkConfigMapWith("net.interface.1-5.config.dhcpClient4.enabled", true); givenNetworkConfigMapWith("net.interface.1-5.config.apn", "myAwesomeAPN"); @@ -730,6 +735,7 @@ public void configurationEnforcementShouldTriggerWithExternalChangeSignal() thro givenMockedDeviceList(); givenNetworkConfigMapWith("net.interfaces", "eth0"); + givenNetworkConfigMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusDisabled"); givenNetworkConfigMapWith("net.interface.eth0.config.dhcpClient4.enabled", false); givenNetworkConfigMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusEnabledWAN"); givenNetworkConfigMapWith("net.interface.eth0.config.ip4.address", "192.168.0.12"); @@ -756,6 +762,7 @@ public void configurationEnforcementShouldTriggerWithExternalDisconnect() throws givenMockedDeviceList(); givenNetworkConfigMapWith("net.interfaces", "eth0"); + givenNetworkConfigMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusDisabled"); givenNetworkConfigMapWith("net.interface.eth0.config.dhcpClient4.enabled", false); givenNetworkConfigMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusEnabledWAN"); givenNetworkConfigMapWith("net.interface.eth0.config.ip4.address", "192.168.0.12"); 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 1a8391fdfa3..4b645bf212b 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 @@ -16,7 +16,10 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import java.net.InetAddress; +import java.net.UnknownHostException; import java.nio.charset.StandardCharsets; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -163,6 +166,100 @@ public void buildIpv4SettingsShouldWorkWhenGivenExpectedMapAndDhcpIsFalseAndUnma thenResultingMapContains("address-data", buildAddressDataWith("192.168.0.12", new UInt32(25))); } + @Test + public void buildIpv6SettingsShouldWorkWhenGivenExpectedMapWithAutoMethodAndWAN() { + 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 buildIpv6SettingsShouldWorkWhenGivenExpectedMapWithDhcpMethodAndWAN() { + 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 buildIpv6SettingsShouldWorkWhenGivenExpectedMapWithManualMethodAndEnabledForWan() { + 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", buildDnsAddressesList("2001:4860:4860:0:0:0:0:8844")); + thenResultingMapContains("ignore-auto-dns", true); + thenResultingMapContains("gateway", "fe80::eed:f0a1:d03a:1"); + + } + + @Test + public void buildIpv6SettingsShouldWorkWhenGivenExpectedMapWithAutoMethodAndEnabledForLan() { + 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 buildIpv6SettingsShouldWorkWhenGivenExpectedMapWithManualMethodAndEnabledForLan() { + + 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 buildIpv6SettingsShouldWorkWhenGivenExpectedMapWithManualMethodAndUnmanaged() { + 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 build80211WirelessSettingsShouldWorkWhenGivenExpectedMapAndSetToInfraAndWithChannelField() { @@ -706,6 +803,12 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiUnmanged() 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", "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"); @@ -721,9 +824,10 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiUnmanged() NMDeviceType.NM_DEVICE_TYPE_WIFI); thenNoExceptionsHaveBeenThrown(); - thenResultingBuildAllMapContains("ipv6", "method", "disabled"); thenResultingBuildAllMapContains("ipv4", "method", "manual"); thenResultingBuildAllMapContains("ipv4", "address-data", buildAddressDataWith("192.168.0.12", new UInt32(25))); + thenResultingBuildAllMapContains("ipv6", "method", "manual"); + thenResultingMapContains("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"); @@ -747,6 +851,12 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiLan() { 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", "netIPv6StatusManagedLAN"); + 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"); @@ -763,9 +873,10 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiLan() { NMDeviceType.NM_DEVICE_TYPE_WIFI); thenNoExceptionsHaveBeenThrown(); - thenResultingBuildAllMapContains("ipv6", "method", "disabled"); thenResultingBuildAllMapContains("ipv4", "method", "manual"); thenResultingBuildAllMapContains("ipv4", "address-data", buildAddressDataWith("192.168.0.12", new UInt32(25))); + thenResultingBuildAllMapContains("ipv6", "method", "manual"); + thenResultingMapContains("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"); @@ -783,6 +894,7 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiLan() { @Test public void buildSettingsShouldWorkWithExpectedConfiguredForInputsWiFiWan() { + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusDisabled"); givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusManagedWan"); givenMapWith("net.interface.wlan0.config.ip4.address", "192.168.0.12"); @@ -824,6 +936,7 @@ public void buildSettingsShouldWorkWithExpectedConfiguredForInputsWiFiWan() { @Test public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiLanAndHiddenSsid() { + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusDisabled"); givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusManagedLan"); givenMapWith("net.interface.wlan0.config.ip4.address", "192.168.0.12"); @@ -867,6 +980,7 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiLanAndHidd @Test public void buildSettingsShouldNotSet80211WirelessSecuritySettingsIfSecurityTypeIsSetToNone() { + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusDisabled"); givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusManagedLan"); givenMapWith("net.interface.wlan0.config.ip4.address", "192.168.0.12"); @@ -903,6 +1017,7 @@ public void buildSettingsShouldNotSet80211WirelessSecuritySettingsIfSecurityType @Test public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiWanAndHiddenSsid() { + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusDisabled"); givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusManagedWan"); givenMapWith("net.interface.wlan0.config.ip4.address", "192.168.0.12"); @@ -946,6 +1061,7 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiWanAndHidd @Test public void buildSettingsShouldWorkWithExpectedInputsConfiguredForEthernetAndUnmanaged() { + givenMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusDisabled"); givenMapWith("net.interface.eth0.config.dhcpClient4.enabled", false); givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusUnmanaged"); givenMapWith("net.interface.eth0.config.ip4.address", "192.168.0.12"); @@ -968,6 +1084,7 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForEthernetAndUnm @Test public void buildSettingsShouldWorkWithExpectedInputsConfiguredForEthernetAndLan() { + givenMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusDisabled"); givenMapWith("net.interface.eth0.config.dhcpClient4.enabled", false); givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusManagedLan"); givenMapWith("net.interface.eth0.config.ip4.address", "192.168.0.12"); @@ -990,6 +1107,7 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForEthernetAndLan @Test public void buildSettingsShouldWorkWithExpectedInputsEthernetAndWan() { + givenMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusDisabled"); givenMapWith("net.interface.eth0.config.dhcpClient4.enabled", false); givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusManagedWan"); givenMapWith("net.interface.eth0.config.ip4.address", "192.168.0.12"); @@ -1012,6 +1130,7 @@ public void buildSettingsShouldWorkWithExpectedInputsEthernetAndWan() { @Test public void buildSettingsShouldWorkWithModemSettings() { + givenMapWith("net.interface.1-1.1.config.ip6.status", "netIPv6StatusDisabled"); 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"); @@ -1382,4 +1501,27 @@ public Object buildAddressDataWith(String ipAddr, UInt32 prefix) { return dataVariant.getValue(); } + + public List> buildDnsAddressesList(String inputDns) { + List> dnsAddresses = new ArrayList<>(); + + InetAddress address; + + try { + address = InetAddress.getByName(inputDns); + } catch (UnknownHostException ex) { + address = null; + } + + byte[] dnsByteArray = address.getAddress(); + + List dnsAddress = new ArrayList<>(); + for (int i = 0; i < dnsByteArray.length; i++) { + dnsAddress.add(dnsByteArray[i]); + } + + dnsAddresses.add(dnsAddress); + + return dnsAddresses; + } } From 1c923acea7a5aaff7e3fa369ca5eb89804d6b568 Mon Sep 17 00:00:00 2001 From: SimoneFiorani Date: Wed, 26 Jul 2023 09:30:00 +0200 Subject: [PATCH 05/11] test(nm): Adding Ip6 tests Signed-off-by: SimoneFiorani --- .../NMSettingsConverterTest.java | 289 ++++++++++++++++-- 1 file changed, 257 insertions(+), 32 deletions(-) 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 4b645bf212b..9b304d39c50 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 @@ -876,7 +876,8 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiLan() { thenResultingBuildAllMapContains("ipv4", "method", "manual"); thenResultingBuildAllMapContains("ipv4", "address-data", buildAddressDataWith("192.168.0.12", new UInt32(25))); thenResultingBuildAllMapContains("ipv6", "method", "manual"); - thenResultingMapContains("address-data", buildAddressDataWith("fe80::eed:f0a1:d03a:1028", new UInt32(25))); + 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"); @@ -894,13 +895,18 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiLan() { @Test public void buildSettingsShouldWorkWithExpectedConfiguredForInputsWiFiWan() { - givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusDisabled"); givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusManagedWan"); 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", "netIPv6StatusManagedWAN"); + 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"); @@ -916,9 +922,11 @@ public void buildSettingsShouldWorkWithExpectedConfiguredForInputsWiFiWan() { NMDeviceType.NM_DEVICE_TYPE_WIFI); thenNoExceptionsHaveBeenThrown(); - thenResultingBuildAllMapContains("ipv6", "method", "disabled"); thenResultingBuildAllMapContains("ipv4", "method", "manual"); thenResultingBuildAllMapContains("ipv4", "address-data", buildAddressDataWith("192.168.0.12", new UInt32(25))); + 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"); @@ -936,13 +944,18 @@ public void buildSettingsShouldWorkWithExpectedConfiguredForInputsWiFiWan() { @Test public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiLanAndHiddenSsid() { - givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusDisabled"); givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusManagedLan"); 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", "netIPv6StatusManagedLan"); + 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"); @@ -959,9 +972,11 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiLanAndHidd NMDeviceType.NM_DEVICE_TYPE_WIFI); thenNoExceptionsHaveBeenThrown(); - thenResultingBuildAllMapContains("ipv6", "method", "disabled"); thenResultingBuildAllMapContains("ipv4", "method", "manual"); thenResultingBuildAllMapContains("ipv4", "address-data", buildAddressDataWith("192.168.0.12", new UInt32(25))); + 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"); @@ -980,13 +995,18 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiLanAndHidd @Test public void buildSettingsShouldNotSet80211WirelessSecuritySettingsIfSecurityTypeIsSetToNone() { - givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusDisabled"); givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusManagedLan"); 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", "netIPv6StatusManagedLan"); + 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"); @@ -1002,9 +1022,11 @@ public void buildSettingsShouldNotSet80211WirelessSecuritySettingsIfSecurityType NMDeviceType.NM_DEVICE_TYPE_WIFI); thenNoExceptionsHaveBeenThrown(); - thenResultingBuildAllMapContains("ipv6", "method", "disabled"); thenResultingBuildAllMapContains("ipv4", "method", "manual"); thenResultingBuildAllMapContains("ipv4", "address-data", buildAddressDataWith("192.168.0.12", new UInt32(25))); + 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"); @@ -1017,13 +1039,18 @@ public void buildSettingsShouldNotSet80211WirelessSecuritySettingsIfSecurityType @Test public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiWanAndHiddenSsid() { - givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusDisabled"); givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusManagedWan"); 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", "netIPv6StatusManagedWan"); + 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"); @@ -1040,9 +1067,11 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiWanAndHidd NMDeviceType.NM_DEVICE_TYPE_WIFI); thenNoExceptionsHaveBeenThrown(); - thenResultingBuildAllMapContains("ipv6", "method", "disabled"); thenResultingBuildAllMapContains("ipv4", "method", "manual"); thenResultingBuildAllMapContains("ipv4", "address-data", buildAddressDataWith("192.168.0.12", new UInt32(25))); + 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"); @@ -1061,45 +1090,51 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiWanAndHidd @Test public void buildSettingsShouldWorkWithExpectedInputsConfiguredForEthernetAndUnmanaged() { - givenMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusDisabled"); givenMapWith("net.interface.eth0.config.dhcpClient4.enabled", false); givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusUnmanaged"); 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", "netIPv6StatusUnmanaged"); + 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("ipv6", "method", "disabled"); - thenResultingBuildAllMapContains("ipv4", "method", "manual"); - thenResultingBuildAllMapContains("ipv4", "address-data", buildAddressDataWith("192.168.0.12", new UInt32(25))); - thenResultingBuildAllMapContains("connection", "id", "kura-eth0-connection"); - thenResultingBuildAllMapContains("connection", "interface-name", "eth0"); - thenResultingBuildAllMapContains("connection", "type", "802-3-ethernet"); + thenIllegalArgumentExceptionThrown(); } @Test public void buildSettingsShouldWorkWithExpectedInputsConfiguredForEthernetAndLan() { - givenMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusDisabled"); givenMapWith("net.interface.eth0.config.dhcpClient4.enabled", false); givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusManagedLan"); 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", "netIPv6StatusManagedLAN"); + 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("ipv6", "method", "disabled"); thenResultingBuildAllMapContains("ipv4", "method", "manual"); thenResultingBuildAllMapContains("ipv4", "address-data", buildAddressDataWith("192.168.0.12", new UInt32(25))); + thenResultingBuildAllMapContains("ipv6", "method", "manual"); + thenResultingBuildAllMapContains("ipv6", "address-data", + buildAddressDataWith("fe80::eed:f0a1:d03a:1028", new UInt32(25))); thenResultingBuildAllMapContains("connection", "id", "kura-eth0-connection"); thenResultingBuildAllMapContains("connection", "interface-name", "eth0"); thenResultingBuildAllMapContains("connection", "type", "802-3-ethernet"); @@ -1107,22 +1142,29 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForEthernetAndLan @Test public void buildSettingsShouldWorkWithExpectedInputsEthernetAndWan() { - givenMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusDisabled"); givenMapWith("net.interface.eth0.config.dhcpClient4.enabled", false); givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusManagedWan"); 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", "netIPv6StatusManagedLAN"); + 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("ipv6", "method", "disabled"); thenResultingBuildAllMapContains("ipv4", "method", "manual"); thenResultingBuildAllMapContains("ipv4", "address-data", buildAddressDataWith("192.168.0.12", new UInt32(25))); + thenResultingBuildAllMapContains("ipv6", "method", "manual"); + thenResultingBuildAllMapContains("ipv6", "address-data", + buildAddressDataWith("fe80::eed:f0a1:d03a:1028", new UInt32(25))); thenResultingBuildAllMapContains("connection", "id", "kura-eth0-connection"); thenResultingBuildAllMapContains("connection", "interface-name", "eth0"); thenResultingBuildAllMapContains("connection", "type", "802-3-ethernet"); @@ -1130,9 +1172,10 @@ public void buildSettingsShouldWorkWithExpectedInputsEthernetAndWan() { @Test public void buildSettingsShouldWorkWithModemSettings() { - givenMapWith("net.interface.1-1.1.config.ip6.status", "netIPv6StatusDisabled"); 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", "netIPv6StatusManagedWAN"); + 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); @@ -1140,8 +1183,8 @@ public void buildSettingsShouldWorkWithModemSettings() { NMDeviceType.NM_DEVICE_TYPE_MODEM); thenNoExceptionsHaveBeenThrown(); - thenResultingBuildAllMapContains("ipv6", "method", "disabled"); thenResultingBuildAllMapContains("ipv4", "method", "auto"); + thenResultingBuildAllMapContains("ipv6", "method", "auto"); thenResultingBuildAllMapContains("connection", "id", "kura-ttyACM0-connection"); thenResultingBuildAllMapContains("connection", "interface-name", "ttyACM0"); thenResultingBuildAllMapContains("connection", "type", "gsm"); @@ -1150,7 +1193,8 @@ public void buildSettingsShouldWorkWithModemSettings() { } @Test - public void buildSettingsShouldThrowDhcpDisabledAndNullIp() { + public void buildSettingsShouldThrowWithDhcpDisabledAndNullIp4() { + givenMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusDisabled"); givenMapWith("net.interface.eth0.config.dhcpClient4.enabled", false); givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusManagedWan"); givenMapWith("net.interface.eth0.config.ip4.address", null); @@ -1166,7 +1210,25 @@ public void buildSettingsShouldThrowDhcpDisabledAndNullIp() { } @Test - public void buildSettingsShouldThrowDhcpDisabledAndNullPrefix() { + public void buildSettingsShouldThrowDhcpDisabledAndNullIp6() { + givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusDisabled"); + givenMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusManagedWan"); + 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 buildSettingsShouldThrowDhcpDisabledAndNullPrefixIp4() { + givenMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusDisabled"); givenMapWith("net.interface.eth0.config.dhcpClient4.enabled", false); givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusManagedWan"); givenMapWith("net.interface.eth0.config.ip4.address", "192.168.0.12"); @@ -1182,7 +1244,25 @@ public void buildSettingsShouldThrowDhcpDisabledAndNullPrefix() { } @Test - public void buildSettingsShouldThrowDhcpDisabledAndNullStatus() { + public void buildSettingsShouldThrowDhcpDisabledAndNullPrefixIp6() { + givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusDisabled"); + givenMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusManagedWan"); + 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 buildSettingsShouldThrowDhcpDisabledAndNullStatusIp4() { + givenMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusDisabled"); 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"); @@ -1198,7 +1278,25 @@ public void buildSettingsShouldThrowDhcpDisabledAndNullStatus() { } @Test - public void buildSettingsShouldThrowDhcpDisabledAndNullWifiSsid() { + public void buildSettingsShouldThrowDhcpDisabledAndNullStatusIp6() { + givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusDisabled"); + givenMapWith("net.interface.eth0.config.ip6.status", null); + 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); + + thenNoSuchElementExceptionThrown(); + } + + @Test + public void buildSettingsShouldThrowDhcpDisabledAndNullWifiSsidIp4() { + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusDisabled"); givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusManagedWan"); givenMapWith("net.interface.wlan0.config.ip4.address", "192.168.0.12"); @@ -1224,7 +1322,35 @@ public void buildSettingsShouldThrowDhcpDisabledAndNullWifiSsid() { } @Test - public void buildSettingsShouldThrowDhcpDisabledAndNullWifiPassword() { + public void buildSettingsShouldThrowDhcpDisabledAndNullWifiSsidIp6() { + givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusDisabled"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusManagedWAN"); + 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 buildSettingsShouldThrowDhcpDisabledAndNullWifiPasswordIp4() { + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusDisabled"); givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusManagedWan"); givenMapWith("net.interface.wlan0.config.ip4.address", "192.168.0.12"); @@ -1250,7 +1376,35 @@ public void buildSettingsShouldThrowDhcpDisabledAndNullWifiPassword() { } @Test - public void buildSettingsShouldThrowDhcpDisabledAndNullWifiSecurityType() { + public void buildSettingsShouldThrowDhcpDisabledAndNullWifiPasswordIp6() { + givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusDisabled"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusManagedWAN"); + 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 buildSettingsShouldThrowDhcpDisabledAndNullWifiSecurityTypeIp4() { + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusDisabled"); givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusManagedWan"); givenMapWith("net.interface.wlan0.config.ip4.address", "192.168.0.12"); @@ -1276,7 +1430,35 @@ public void buildSettingsShouldThrowDhcpDisabledAndNullWifiSecurityType() { } @Test - public void shouldSupportEmptyWanPriorityProperty() { + public void buildSettingsShouldThrowDhcpDisabledAndNullWifiSecurityTypeIp6() { + givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusDisabled"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusManagedWAN"); + 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 shouldSupportEmptyWanPriorityPropertyIp4() { + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusDisabled"); givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", true); givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusEnabledWAN"); givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); @@ -1288,7 +1470,21 @@ public void shouldSupportEmptyWanPriorityProperty() { } @Test - public void shouldPopulateWanPriorityProperty() { + public void shouldSupportEmptyWanPriorityPropertyIp6() { + givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusDisabled"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusManagedWAN"); + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodAuto"); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildIpv6SettingsIsRunWith(this.networkProperties, "wlan0"); + + thenNoExceptionsHaveBeenThrown(); + thenResultingMapNotContains("route-metric"); + } + + @Test + public void shouldPopulateWanPriorityPropertyIp4() { + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusDisabled"); givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", true); givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusEnabledWAN"); givenMapWith("net.interface.wlan0.config.ip4.wan.priority", new Integer(30)); @@ -1301,7 +1497,22 @@ public void shouldPopulateWanPriorityProperty() { } @Test - public void shouldNotPopulateWanPriorityPropertyIfNotWAN() { + public void shouldPopulateWanPriorityPropertyIp6() { + givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusDisabled"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledWAN"); + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodAuto"); + givenMapWith("net.interface.wlan0.config.ip6.wan.priority", new Integer(30)); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildIpv6SettingsIsRunWith(this.networkProperties, "wlan0"); + + thenNoExceptionsHaveBeenThrown(); + thenResultingMapContains("route-metric", new Variant<>(new Long(30)).getValue()); + } + + @Test + public void shouldNotPopulateWanPriorityPropertyIfNotWANIp4() { + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusDisabled"); givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", true); givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusEnabledLAN"); givenMapWith("net.interface.wlan0.config.ip4.wan.priority", new Integer(30)); @@ -1313,6 +1524,20 @@ public void shouldNotPopulateWanPriorityPropertyIfNotWAN() { thenResultingMapNotContains("route-metric"); } + @Test + public void shouldNotPopulateWanPriorityPropertyIfNotWANIp6() { + givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusDisabled"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledLAN"); + givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodAuto"); + givenMapWith("net.interface.wlan0.config.ip6.wan.priority", new Integer(30)); + givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); + + whenBuildIpv6SettingsIsRunWith(this.networkProperties, "wlan0"); + + thenNoExceptionsHaveBeenThrown(); + thenResultingMapNotContains("route-metric"); + } + /* * Given */ From aebc0c7d11ee598df747f1d46762782c891c8b71 Mon Sep 17 00:00:00 2001 From: SimoneFiorani Date: Wed, 26 Jul 2023 15:07:01 +0200 Subject: [PATCH 06/11] feat(nm): refactoring of methods and tests Signed-off-by: SimoneFiorani --- .../kura/nm/KuraIp6AddressGenerationMode.java | 10 --- .../kura/nm/KuraIp6ConfigurationMethod.java | 10 --- .../org/eclipse/kura/nm/KuraIp6Privacy.java | 12 +-- .../org/eclipse/kura/nm/KuraIpStatus.java | 31 ++++++++ .../org/eclipse/kura/nm/NMDbusConnector.java | 13 ++- .../nm/configuration/NMSettingsConverter.java | 46 ++++++----- .../eclipse/kura/nm/NMDbusConnectorTest.java | 2 +- .../NMSettingsConverterTest.java | 79 ++++++++----------- 8 files changed, 101 insertions(+), 102 deletions(-) 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 index df7b12373c1..a28d2f1abe2 100644 --- 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 @@ -1,8 +1,5 @@ package org.eclipse.kura.nm; -import java.util.Arrays; -import java.util.List; - import org.eclipse.kura.nm.enums.NMSettingIP6ConfigAddrGenMode; public enum KuraIp6AddressGenerationMode { @@ -10,13 +7,6 @@ public enum KuraIp6AddressGenerationMode { EUI64, STABLE_PRIVACY; - private static final List ADDRESS_GEN_MODE = Arrays - .asList(KuraIp6AddressGenerationMode.EUI64, KuraIp6AddressGenerationMode.STABLE_PRIVACY); - - public static Boolean isEnabled(KuraIp6AddressGenerationMode status) { - return ADDRESS_GEN_MODE.contains(status); - } - public static KuraIp6AddressGenerationMode fromString(String status) { switch (status) { case "netIPv6AddressGenModeEUI64": 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 index b5cec7c2dff..ddbe63dabb5 100644 --- 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 @@ -13,9 +13,6 @@ package org.eclipse.kura.nm; -import java.util.Arrays; -import java.util.List; - public enum KuraIp6ConfigurationMethod { AUTO, @@ -23,13 +20,6 @@ public enum KuraIp6ConfigurationMethod { MANUAL, UNKNOWN; - private static final List ENABLED_STATUS = Arrays.asList( - KuraIp6ConfigurationMethod.AUTO, KuraIp6ConfigurationMethod.DHCP, KuraIp6ConfigurationMethod.MANUAL); - - public static Boolean isEnabled(KuraIp6ConfigurationMethod status) { - return ENABLED_STATUS.contains(status); - } - public static KuraIp6ConfigurationMethod fromString(String status) { switch (status) { case "netIPv6MethodAuto": 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 index 1221534b442..4e4552ca062 100644 --- 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 @@ -1,8 +1,5 @@ package org.eclipse.kura.nm; -import java.util.Arrays; -import java.util.List; - import org.eclipse.kura.nm.enums.NMSettingIP6ConfigPrivacy; public enum KuraIp6Privacy { @@ -12,13 +9,6 @@ public enum KuraIp6Privacy { ENABLED_PUBLIC_ADD, ENABLED_TEMP_ADD; - private static final List ENABLED_STATUS = Arrays.asList(KuraIp6Privacy.UNKNOWN, - KuraIp6Privacy.DISABLED, KuraIp6Privacy.ENABLED_PUBLIC_ADD, KuraIp6Privacy.ENABLED_TEMP_ADD); - - public static Boolean isEnabled(KuraIp6Privacy status) { - return ENABLED_STATUS.contains(status); - } - public static KuraIp6Privacy fromString(String status) { switch (status) { case "netIPv6PrivacyUnknown": @@ -30,7 +20,7 @@ public static KuraIp6Privacy fromString(String status) { case "netIPv6PrivacyEnabledTempAdd": return KuraIp6Privacy.ENABLED_TEMP_ADD; default: - return KuraIp6Privacy.UNKNOWN; + throw new IllegalArgumentException(String.format("Unsupported IPv6 privacy value: \"%s\"", status)); } } 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 8f5ba0eec6f..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)); - KuraIpStatus ip6Status = KuraIpStatus - .fromString(properties.get(String.class, "net.interface.%s.config.ip6.status", deviceId)); + + 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 9613ff483a2..5d2ecc13f47 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 @@ -151,17 +151,23 @@ public static Map> buildIpv4Settings(NetworkProperties props, public static Map> buildIpv6Settings(NetworkProperties props, String deviceId) { - KuraIpStatus ip6Status = KuraIpStatus - .fromString(props.get(String.class, "net.interface.%s.config.ip6.status", deviceId)); + // buildIpv6Settings doesn't support Unmanaged status. Therefore if ip6.status property is not set, it assumes + // it is disabled. - if (ip6Status == KuraIpStatus.UNMANAGED) { + 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<>(); + if (ip6Status == KuraIpStatus.DISABLED) { - settings.put(NM_SETTINGS_IPV4_METHOD, new Variant<>("disabled")); + settings.put(NM_SETTINGS_IPV6_METHOD, new Variant<>("disabled")); return settings; } @@ -172,6 +178,22 @@ public static Map> buildIpv6Settings(NetworkProperties props, settings.put(NM_SETTINGS_IPV6_METHOD, new Variant<>("auto")); + Optional addressGenerationMode = props.getOpt(String.class, + "net.interface.%s.config.ip6.addr.gen.mode", deviceId); + if (addressGenerationMode.isPresent()) { + 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); + if (privacy.isPresent()) { + 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")); @@ -222,22 +244,6 @@ public static Map> buildIpv6Settings(NetworkProperties props, logger.warn("Unexpected ip status received: \"{}\". Ignoring", ip6Status); } - Optional addressGenerationMode = props.getOpt(String.class, "net.interface.%s.config.ip6.addr.gen.mode", - deviceId); - if (addressGenerationMode.isPresent()) { - 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); - if (privacy.isPresent()) { - KuraIp6Privacy ip6Privacy = KuraIp6Privacy.fromString(privacy.get()); - settings.put("ip6-privacy", - new Variant<>(KuraIp6Privacy.toNMSettingIP6ConfigPrivacy(ip6Privacy).toInt32())); - } - return settings; } diff --git a/kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/NMDbusConnectorTest.java b/kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/NMDbusConnectorTest.java index 536f4502ea8..efbb1ab5485 100644 --- a/kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/NMDbusConnectorTest.java +++ b/kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/NMDbusConnectorTest.java @@ -75,6 +75,7 @@ import org.freedesktop.dbus.connections.impl.DBusConnection; import org.freedesktop.dbus.exceptions.DBusException; import org.freedesktop.dbus.exceptions.DBusExecutionException; +import org.freedesktop.dbus.interfaces.ObjectManager; import org.freedesktop.dbus.interfaces.Properties; import org.freedesktop.dbus.types.UInt32; import org.freedesktop.dbus.types.UInt64; @@ -404,7 +405,6 @@ public void applyShouldWorkWithEnabledEthernet() throws DBusException, IOExcepti givenMockedDeviceList(); givenNetworkConfigMapWith("net.interfaces", "eth0"); - givenNetworkConfigMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusDisabled"); givenNetworkConfigMapWith("net.interface.eth0.config.dhcpClient4.enabled", false); givenNetworkConfigMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusEnabledWAN"); givenNetworkConfigMapWith("net.interface.eth0.config.ip4.address", "192.168.0.12"); 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 9b304d39c50..2ae40ecae83 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 @@ -167,7 +167,7 @@ public void buildIpv4SettingsShouldWorkWhenGivenExpectedMapAndDhcpIsFalseAndUnma } @Test - public void buildIpv6SettingsShouldWorkWhenGivenExpectedMapWithAutoMethodAndWAN() { + public void buildIpv6SettingsShouldWorkWhenGivenExpectedMapWithAutoEnableAndWAN() { givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodAuto"); givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledWAN"); @@ -179,7 +179,7 @@ public void buildIpv6SettingsShouldWorkWhenGivenExpectedMapWithAutoMethodAndWAN( } @Test - public void buildIpv6SettingsShouldWorkWhenGivenExpectedMapWithDhcpMethodAndWAN() { + public void buildIpv6SettingsShouldWorkWhenGivenExpectedMapWithDhcpEnableAndWAN() { givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodDhcp"); givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledWAN"); @@ -191,7 +191,7 @@ public void buildIpv6SettingsShouldWorkWhenGivenExpectedMapWithDhcpMethodAndWAN( } @Test - public void buildIpv6SettingsShouldWorkWhenGivenExpectedMapWithManualMethodAndEnabledForWan() { + 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"); @@ -212,7 +212,7 @@ public void buildIpv6SettingsShouldWorkWhenGivenExpectedMapWithManualMethodAndEn } @Test - public void buildIpv6SettingsShouldWorkWhenGivenExpectedMapWithAutoMethodAndEnabledForLan() { + public void buildIpv6SettingsShouldWorkWhenGivenExpectedMapWithAutoEnableAndEnabledForLan() { givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodAuto"); givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledLAN"); givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); @@ -226,7 +226,7 @@ public void buildIpv6SettingsShouldWorkWhenGivenExpectedMapWithAutoMethodAndEnab } @Test - public void buildIpv6SettingsShouldWorkWhenGivenExpectedMapWithManualMethodAndEnabledForLan() { + public void buildIpv6SettingsShouldWorkWhenGivenExpectedMapWithManualEnableAndEnabledForLan() { givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodManual"); givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledLAN"); @@ -246,7 +246,7 @@ public void buildIpv6SettingsShouldWorkWhenGivenExpectedMapWithManualMethodAndEn } @Test - public void buildIpv6SettingsShouldWorkWhenGivenExpectedMapWithManualMethodAndUnmanaged() { + public void buildIpv6SettingsShouldWorkWhenGivenExpectedMapWithManualEnableAndUnmanaged() { 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"); @@ -823,35 +823,18 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiUnmanged() 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("ipv6", "method", "manual"); - thenResultingMapContains("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()); + thenIllegalArgumentExceptionThrown(); } @Test public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiLan() { givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); - givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusManagedLan"); + 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.ip4.dnsServers", "1.1.1.1"); givenMapWith("net.interface.wlan0.config.ip4.gateway", "192.168.0.1"); - givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusManagedLAN"); + 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); @@ -896,12 +879,12 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiLan() { @Test public void buildSettingsShouldWorkWithExpectedConfiguredForInputsWiFiWan() { givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); - givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusManagedWan"); + 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", "netIPv6StatusManagedWAN"); + 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); @@ -945,12 +928,12 @@ public void buildSettingsShouldWorkWithExpectedConfiguredForInputsWiFiWan() { @Test public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiLanAndHiddenSsid() { givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); - givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusManagedLan"); + 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.ip4.dnsServers", "1.1.1.1"); givenMapWith("net.interface.wlan0.config.ip4.gateway", "192.168.0.1"); - givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusManagedLan"); + 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); @@ -996,12 +979,12 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiLanAndHidd @Test public void buildSettingsShouldNotSet80211WirelessSecuritySettingsIfSecurityTypeIsSetToNone() { givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); - givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusManagedLan"); + 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.ip4.dnsServers", "1.1.1.1"); givenMapWith("net.interface.wlan0.config.ip4.gateway", "192.168.0.1"); - givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusManagedLan"); + 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); @@ -1040,12 +1023,12 @@ public void buildSettingsShouldNotSet80211WirelessSecuritySettingsIfSecurityType @Test public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiWanAndHiddenSsid() { givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); - givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusManagedWan"); + 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", "netIPv6StatusManagedWan"); + 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); @@ -1113,12 +1096,12 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForEthernetAndUnm @Test public void buildSettingsShouldWorkWithExpectedInputsConfiguredForEthernetAndLan() { givenMapWith("net.interface.eth0.config.dhcpClient4.enabled", false); - givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusManagedLan"); + 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.ip4.dnsServers", "1.1.1.1"); givenMapWith("net.interface.eth0.config.ip4.gateway", "192.168.0.1"); - givenMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusManagedLAN"); + 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); @@ -1143,12 +1126,12 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForEthernetAndLan @Test public void buildSettingsShouldWorkWithExpectedInputsEthernetAndWan() { givenMapWith("net.interface.eth0.config.dhcpClient4.enabled", false); - givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusManagedWan"); + 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", "netIPv6StatusManagedLAN"); + 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); @@ -1174,7 +1157,7 @@ public void buildSettingsShouldWorkWithExpectedInputsEthernetAndWan() { public void buildSettingsShouldWorkWithModemSettings() { 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", "netIPv6StatusManagedWAN"); + 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); @@ -1196,7 +1179,7 @@ public void buildSettingsShouldWorkWithModemSettings() { public void buildSettingsShouldThrowWithDhcpDisabledAndNullIp4() { givenMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusDisabled"); givenMapWith("net.interface.eth0.config.dhcpClient4.enabled", false); - givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusManagedWan"); + 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"); @@ -1212,7 +1195,7 @@ public void buildSettingsShouldThrowWithDhcpDisabledAndNullIp4() { @Test public void buildSettingsShouldThrowDhcpDisabledAndNullIp6() { givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusDisabled"); - givenMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusManagedWan"); + 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); @@ -1230,7 +1213,7 @@ public void buildSettingsShouldThrowDhcpDisabledAndNullIp6() { public void buildSettingsShouldThrowDhcpDisabledAndNullPrefixIp4() { givenMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusDisabled"); givenMapWith("net.interface.eth0.config.dhcpClient4.enabled", false); - givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusManagedWan"); + 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"); @@ -1246,7 +1229,7 @@ public void buildSettingsShouldThrowDhcpDisabledAndNullPrefixIp4() { @Test public void buildSettingsShouldThrowDhcpDisabledAndNullPrefixIp6() { givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusDisabled"); - givenMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusManagedWan"); + 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); @@ -1298,7 +1281,7 @@ public void buildSettingsShouldThrowDhcpDisabledAndNullStatusIp6() { public void buildSettingsShouldThrowDhcpDisabledAndNullWifiSsidIp4() { givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusDisabled"); givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); - givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusManagedWan"); + 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"); @@ -1352,7 +1335,7 @@ public void buildSettingsShouldThrowDhcpDisabledAndNullWifiSsidIp6() { public void buildSettingsShouldThrowDhcpDisabledAndNullWifiPasswordIp4() { givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusDisabled"); givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); - givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusManagedWan"); + 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"); @@ -1406,7 +1389,7 @@ public void buildSettingsShouldThrowDhcpDisabledAndNullWifiPasswordIp6() { public void buildSettingsShouldThrowDhcpDisabledAndNullWifiSecurityTypeIp4() { givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusDisabled"); givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); - givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusManagedWan"); + 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"); @@ -1472,7 +1455,7 @@ public void shouldSupportEmptyWanPriorityPropertyIp4() { @Test public void shouldSupportEmptyWanPriorityPropertyIp6() { givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusDisabled"); - givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusManagedWAN"); + givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledWAN"); givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodAuto"); givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); @@ -1711,7 +1694,7 @@ public void thenNoExceptionsHaveBeenThrown() { } /* - * Helper Methods + * Helper Enables */ public Object buildAddressDataWith(String ipAddr, UInt32 prefix) { From f2bd9e1753b72e5f513fe720892e599a26c43456 Mon Sep 17 00:00:00 2001 From: SimoneFiorani Date: Thu, 27 Jul 2023 12:07:37 +0200 Subject: [PATCH 07/11] refactor(nm): Sonar complexity problem resolved, test refactoring Signed-off-by: SimoneFiorani --- .../nm/configuration/NMSettingsConverter.java | 32 ++++++++++--------- .../eclipse/kura/nm/NMDbusConnectorTest.java | 1 - .../NMSettingsConverterTest.java | 31 +++--------------- 3 files changed, 21 insertions(+), 43 deletions(-) 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 5d2ecc13f47..87cc7a88e1c 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 @@ -43,6 +43,7 @@ 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_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"; @@ -126,14 +127,14 @@ public static Map> buildIpv4Settings(NetworkProperties props, } if (ip4Status.equals(KuraIpStatus.ENABLEDLAN)) { - settings.put("ignore-auto-dns", new Variant<>(true)); + settings.put(NM_SETTINGS_IPV6_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_IPV6_IGNORE_AUTO_DNS, new Variant<>(true)); } Optional wanPriority = props.getOpt(Integer.class, "net.interface.%s.config.ip4.wan.priority", @@ -180,19 +181,20 @@ public static Map> buildIpv6Settings(NetworkProperties props, Optional addressGenerationMode = props.getOpt(String.class, "net.interface.%s.config.ip6.addr.gen.mode", deviceId); - if (addressGenerationMode.isPresent()) { + + 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); - if (privacy.isPresent()) { + 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)) { @@ -223,23 +225,23 @@ public static Map> buildIpv6Settings(NetworkProperties props, } if (ip6Status.equals(KuraIpStatus.ENABLEDLAN)) { - settings.put("ignore-auto-dns", new Variant<>(true)); + 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); - if (dnsServers.isPresent()) { - settings.put("dns", new Variant<>(convertIp6(dnsServers.get()), "aay")); - settings.put("ignore-auto-dns", new Variant<>(true)); - } + + 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); - if (wanPriority.isPresent()) { - Long supportedByNM = wanPriority.get().longValue(); - settings.put("route-metric", new Variant<>(supportedByNM)); - } + + wanPriority.ifPresent(value -> settings.put("route-metric", new Variant<>(value.longValue()))); + } else { logger.warn("Unexpected ip status received: \"{}\". Ignoring", ip6Status); } diff --git a/kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/NMDbusConnectorTest.java b/kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/NMDbusConnectorTest.java index efbb1ab5485..31b89dbc00b 100644 --- a/kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/NMDbusConnectorTest.java +++ b/kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/NMDbusConnectorTest.java @@ -75,7 +75,6 @@ import org.freedesktop.dbus.connections.impl.DBusConnection; import org.freedesktop.dbus.exceptions.DBusException; import org.freedesktop.dbus.exceptions.DBusExecutionException; -import org.freedesktop.dbus.interfaces.ObjectManager; import org.freedesktop.dbus.interfaces.Properties; import org.freedesktop.dbus.types.UInt32; import org.freedesktop.dbus.types.UInt64; 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 2ae40ecae83..904f0a5a849 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 @@ -16,10 +16,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import java.net.InetAddress; -import java.net.UnknownHostException; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -54,6 +51,9 @@ public class NMSettingsConverterTest { Boolean hasAnIllegalArgumentExceptionThrown = false; Boolean hasAGenericExecptionBeenThrown = false; + private static List> expectedDnsList = Arrays + .asList(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); @@ -205,7 +205,7 @@ public void buildIpv6SettingsShouldWorkWhenGivenExpectedMapWithManualEnableAndEn thenNoExceptionsHaveBeenThrown(); thenResultingMapContains("method", "manual"); thenResultingMapContains("address-data", buildAddressDataWith("fe80::eed:f0a1:d03a:1028", new UInt32(25))); - thenResultingMapContains("dns", buildDnsAddressesList("2001:4860:4860:0:0:0:0:8844")); + thenResultingMapContains("dns", expectedDnsList); thenResultingMapContains("ignore-auto-dns", true); thenResultingMapContains("gateway", "fe80::eed:f0a1:d03a:1"); @@ -1709,27 +1709,4 @@ public Object buildAddressDataWith(String ipAddr, UInt32 prefix) { return dataVariant.getValue(); } - - public List> buildDnsAddressesList(String inputDns) { - List> dnsAddresses = new ArrayList<>(); - - InetAddress address; - - try { - address = InetAddress.getByName(inputDns); - } catch (UnknownHostException ex) { - address = null; - } - - byte[] dnsByteArray = address.getAddress(); - - List dnsAddress = new ArrayList<>(); - for (int i = 0; i < dnsByteArray.length; i++) { - dnsAddress.add(dnsByteArray[i]); - } - - dnsAddresses.add(dnsAddress); - - return dnsAddresses; - } } From 18d09beb44cd23f0cd08df80056b0803fdb13443 Mon Sep 17 00:00:00 2001 From: SimoneFiorani Date: Thu, 27 Jul 2023 12:46:59 +0200 Subject: [PATCH 08/11] refactor(nm): update with PR comments Signed-off-by: SimoneFiorani --- .../kura/nm/KuraIp6AddressGenerationMode.java | 12 ++++++++++++ .../eclipse/kura/nm/KuraIp6ConfigurationMethod.java | 5 ++--- .../java/org/eclipse/kura/nm/KuraIp6Privacy.java | 12 ++++++++++++ .../kura/nm/configuration/NMSettingsConverter.java | 5 +++-- .../kura/nm/enums/NMSettingIP6ConfigAddrGenMode.java | 12 ++++++++++++ .../kura/nm/enums/NMSettingIP6ConfigPrivacy.java | 12 ++++++++++++ .../nm/configuration/NMSettingsConverterTest.java | 8 ++++---- 7 files changed, 57 insertions(+), 9 deletions(-) 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 index a28d2f1abe2..ec2ec59e8a4 100644 --- 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 @@ -1,3 +1,15 @@ +/******************************************************************************* + * 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; 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 index ddbe63dabb5..3ad5caf98e1 100644 --- 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 @@ -17,8 +17,7 @@ public enum KuraIp6ConfigurationMethod { AUTO, DHCP, - MANUAL, - UNKNOWN; + MANUAL; public static KuraIp6ConfigurationMethod fromString(String status) { switch (status) { @@ -29,7 +28,7 @@ public static KuraIp6ConfigurationMethod fromString(String status) { case "netIPv6MethodManual": return KuraIp6ConfigurationMethod.MANUAL; default: - return KuraIp6ConfigurationMethod.UNKNOWN; + throw new IllegalArgumentException(String.format("Unsupported IPv6 configuration method: \"%s\"", status)); } 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 index 4e4552ca062..dc516d638a3 100644 --- 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 @@ -1,3 +1,15 @@ +/******************************************************************************* + * 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; 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 87cc7a88e1c..cf013cb67f2 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 @@ -43,6 +43,7 @@ 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"; @@ -127,14 +128,14 @@ public static Map> buildIpv4Settings(NetworkProperties props, } if (ip4Status.equals(KuraIpStatus.ENABLEDLAN)) { - settings.put(NM_SETTINGS_IPV6_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(NM_SETTINGS_IPV6_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", 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 index 39b8bb18317..5c3cb32be0d 100644 --- 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 @@ -1,3 +1,15 @@ +/******************************************************************************* + * 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 { 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 index c370e022cc3..e083202204e 100644 --- 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 @@ -1,3 +1,15 @@ +/******************************************************************************* + * 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 { 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 904f0a5a849..e66d0ddf5f0 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,8 +51,8 @@ public class NMSettingsConverterTest { Boolean hasAnIllegalArgumentExceptionThrown = false; Boolean hasAGenericExecptionBeenThrown = false; - private static List> expectedDnsList = Arrays - .asList(Arrays.asList(new Byte[] { 32, 1, 72, 96, 72, 96, 0, 0, 0, 0, 0, 0, 0, 0, -120, 68 })); + 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() { @@ -205,7 +205,7 @@ public void buildIpv6SettingsShouldWorkWhenGivenExpectedMapWithManualEnableAndEn thenNoExceptionsHaveBeenThrown(); thenResultingMapContains("method", "manual"); thenResultingMapContains("address-data", buildAddressDataWith("fe80::eed:f0a1:d03a:1028", new UInt32(25))); - thenResultingMapContains("dns", expectedDnsList); + thenResultingMapContains("dns", Arrays.asList(IP6_BYTE_ARRAY_ADDRESS)); thenResultingMapContains("ignore-auto-dns", true); thenResultingMapContains("gateway", "fe80::eed:f0a1:d03a:1"); @@ -1694,7 +1694,7 @@ public void thenNoExceptionsHaveBeenThrown() { } /* - * Helper Enables + * Helper Methods */ public Object buildAddressDataWith(String ipAddr, UInt32 prefix) { From 2d170837d084fdd3a2f0e4fe6ae988d886fa66fe Mon Sep 17 00:00:00 2001 From: SimoneFiorani Date: Thu, 27 Jul 2023 12:52:38 +0200 Subject: [PATCH 09/11] test(nm): Tests restored to initial state Signed-off-by: SimoneFiorani --- .../eclipse/kura/nm/NMDbusConnectorTest.java | 8 +- .../NMSettingsConverterTest.java | 435 +++--------------- 2 files changed, 55 insertions(+), 388 deletions(-) diff --git a/kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/NMDbusConnectorTest.java b/kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/NMDbusConnectorTest.java index 31b89dbc00b..0aa7a062eb3 100644 --- a/kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/NMDbusConnectorTest.java +++ b/kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/NMDbusConnectorTest.java @@ -426,7 +426,6 @@ public void applyShouldWorkWithEnabledEthernetWithoutInitialConnection() throws givenMockToPrepNetworkManagerToAllowDeviceToCreateNewConnection(); givenNetworkConfigMapWith("net.interfaces", "eth0"); - givenNetworkConfigMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusDisabled"); givenNetworkConfigMapWith("net.interface.eth0.config.dhcpClient4.enabled", false); givenNetworkConfigMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusEnabledWAN"); givenNetworkConfigMapWith("net.interface.eth0.config.ip4.address", "192.168.0.12"); @@ -533,7 +532,6 @@ public void applyShouldWorkWithEnabledModem() throws DBusException, IOException givenMockedDeviceList(); givenNetworkConfigMapWith("net.interfaces", "1-5,"); - givenNetworkConfigMapWith("net.interface.1-5.config.ip6.status", "netIPv6StatusDisabled"); givenNetworkConfigMapWith("net.interface.1-5.config.ip4.status", "netIPv4StatusEnabledWAN"); givenNetworkConfigMapWith("net.interface.1-5.config.dhcpClient4.enabled", true); givenNetworkConfigMapWith("net.interface.1-5.config.apn", "myAwesomeAPN"); @@ -556,7 +554,6 @@ public void applyShouldWorkWithModemWithEnabledGPS() throws DBusException, IOExc givenMockedDeviceList(); givenNetworkConfigMapWith("net.interfaces", "1-5,"); - givenNetworkConfigMapWith("net.interface.1-5.config.ip6.status", "netIPv6StatusDisabled"); givenNetworkConfigMapWith("net.interface.1-5.config.ip4.status", "netIPv4StatusEnabledWAN"); givenNetworkConfigMapWith("net.interface.1-5.config.dhcpClient4.enabled", true); givenNetworkConfigMapWith("net.interface.1-5.config.apn", "myAwesomeAPN"); @@ -579,7 +576,6 @@ public void applyShouldDisableGPSWithMissingGPSConfiguration() throws DBusExcept givenMockedDeviceList(); givenNetworkConfigMapWith("net.interfaces", "1-5,"); - givenNetworkConfigMapWith("net.interface.1-5.config.ip6.status", "netIPv6StatusDisabled"); givenNetworkConfigMapWith("net.interface.1-5.config.ip4.status", "netIPv4StatusEnabledWAN"); givenNetworkConfigMapWith("net.interface.1-5.config.dhcpClient4.enabled", true); givenNetworkConfigMapWith("net.interface.1-5.config.apn", "myAwesomeAPN"); @@ -734,7 +730,6 @@ public void configurationEnforcementShouldTriggerWithExternalChangeSignal() thro givenMockedDeviceList(); givenNetworkConfigMapWith("net.interfaces", "eth0"); - givenNetworkConfigMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusDisabled"); givenNetworkConfigMapWith("net.interface.eth0.config.dhcpClient4.enabled", false); givenNetworkConfigMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusEnabledWAN"); givenNetworkConfigMapWith("net.interface.eth0.config.ip4.address", "192.168.0.12"); @@ -761,7 +756,6 @@ public void configurationEnforcementShouldTriggerWithExternalDisconnect() throws givenMockedDeviceList(); givenNetworkConfigMapWith("net.interfaces", "eth0"); - givenNetworkConfigMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusDisabled"); givenNetworkConfigMapWith("net.interface.eth0.config.dhcpClient4.enabled", false); givenNetworkConfigMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusEnabledWAN"); givenNetworkConfigMapWith("net.interface.eth0.config.ip4.address", "192.168.0.12"); @@ -1606,4 +1600,4 @@ private void simulateIwCommandOutputs(String interfaceName, Properties preMocked "/mock/device/" + interfaceName, Wireless.class); } -} +} \ No newline at end of file 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 e66d0ddf5f0..bbc13544b38 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,9 +51,6 @@ 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); @@ -166,100 +163,6 @@ public void buildIpv4SettingsShouldWorkWhenGivenExpectedMapAndDhcpIsFalseAndUnma thenResultingMapContains("address-data", buildAddressDataWith("192.168.0.12", new UInt32(25))); } - @Test - public void buildIpv6SettingsShouldWorkWhenGivenExpectedMapWithAutoEnableAndWAN() { - 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 buildIpv6SettingsShouldWorkWhenGivenExpectedMapWithManualEnableAndUnmanaged() { - 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 build80211WirelessSettingsShouldWorkWhenGivenExpectedMapAndSetToInfraAndWithChannelField() { @@ -803,12 +706,6 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiUnmanged() 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", "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"); @@ -823,23 +720,33 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiUnmanged() whenBuildSettingsIsRunWith(this.networkProperties, Optional.empty(), "wlan0", "wlan0", NMDeviceType.NM_DEVICE_TYPE_WIFI); - thenIllegalArgumentExceptionThrown(); + thenNoExceptionsHaveBeenThrown(); + thenResultingBuildAllMapContains("ipv6", "method", "disabled"); + thenResultingBuildAllMapContains("ipv4", "method", "manual"); + thenResultingBuildAllMapContains("ipv4", "address-data", buildAddressDataWith("192.168.0.12", 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 buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiLan() { givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); - givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusEnabledLan"); + givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusManagedLan"); 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", "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"); @@ -856,11 +763,9 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiLan() { NMDeviceType.NM_DEVICE_TYPE_WIFI); thenNoExceptionsHaveBeenThrown(); + thenResultingBuildAllMapContains("ipv6", "method", "disabled"); thenResultingBuildAllMapContains("ipv4", "method", "manual"); thenResultingBuildAllMapContains("ipv4", "address-data", buildAddressDataWith("192.168.0.12", new UInt32(25))); - 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"); @@ -879,17 +784,11 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiLan() { @Test public void buildSettingsShouldWorkWithExpectedConfiguredForInputsWiFiWan() { givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); - givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusEnabledWAN"); + givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusManagedWan"); 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"); @@ -905,11 +804,9 @@ public void buildSettingsShouldWorkWithExpectedConfiguredForInputsWiFiWan() { NMDeviceType.NM_DEVICE_TYPE_WIFI); thenNoExceptionsHaveBeenThrown(); + thenResultingBuildAllMapContains("ipv6", "method", "disabled"); thenResultingBuildAllMapContains("ipv4", "method", "manual"); thenResultingBuildAllMapContains("ipv4", "address-data", buildAddressDataWith("192.168.0.12", new UInt32(25))); - 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"); @@ -928,17 +825,11 @@ public void buildSettingsShouldWorkWithExpectedConfiguredForInputsWiFiWan() { @Test public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiLanAndHiddenSsid() { givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); - givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusEnabledLAN"); + givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusManagedLan"); 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", "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"); @@ -955,11 +846,9 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiLanAndHidd NMDeviceType.NM_DEVICE_TYPE_WIFI); thenNoExceptionsHaveBeenThrown(); + thenResultingBuildAllMapContains("ipv6", "method", "disabled"); thenResultingBuildAllMapContains("ipv4", "method", "manual"); thenResultingBuildAllMapContains("ipv4", "address-data", buildAddressDataWith("192.168.0.12", new UInt32(25))); - 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"); @@ -979,17 +868,11 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiLanAndHidd @Test public void buildSettingsShouldNotSet80211WirelessSecuritySettingsIfSecurityTypeIsSetToNone() { givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); - givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusEnabledLAN"); + givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusManagedLan"); 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", "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"); @@ -1005,11 +888,9 @@ public void buildSettingsShouldNotSet80211WirelessSecuritySettingsIfSecurityType NMDeviceType.NM_DEVICE_TYPE_WIFI); thenNoExceptionsHaveBeenThrown(); + thenResultingBuildAllMapContains("ipv6", "method", "disabled"); thenResultingBuildAllMapContains("ipv4", "method", "manual"); thenResultingBuildAllMapContains("ipv4", "address-data", buildAddressDataWith("192.168.0.12", new UInt32(25))); - 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"); @@ -1023,17 +904,11 @@ public void buildSettingsShouldNotSet80211WirelessSecuritySettingsIfSecurityType @Test public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiWanAndHiddenSsid() { givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); - givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusEnabledWAN"); + givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusManagedWan"); 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"); @@ -1050,11 +925,9 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForWiFiWanAndHidd NMDeviceType.NM_DEVICE_TYPE_WIFI); thenNoExceptionsHaveBeenThrown(); + thenResultingBuildAllMapContains("ipv6", "method", "disabled"); thenResultingBuildAllMapContains("ipv4", "method", "manual"); thenResultingBuildAllMapContains("ipv4", "address-data", buildAddressDataWith("192.168.0.12", new UInt32(25))); - 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"); @@ -1079,45 +952,37 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForEthernetAndUnm 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", "netIPv6StatusUnmanaged"); - 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); - thenIllegalArgumentExceptionThrown(); + thenNoExceptionsHaveBeenThrown(); + thenResultingBuildAllMapContains("ipv6", "method", "disabled"); + thenResultingBuildAllMapContains("ipv4", "method", "manual"); + thenResultingBuildAllMapContains("ipv4", "address-data", buildAddressDataWith("192.168.0.12", new UInt32(25))); + thenResultingBuildAllMapContains("connection", "id", "kura-eth0-connection"); + thenResultingBuildAllMapContains("connection", "interface-name", "eth0"); + thenResultingBuildAllMapContains("connection", "type", "802-3-ethernet"); } @Test public void buildSettingsShouldWorkWithExpectedInputsConfiguredForEthernetAndLan() { givenMapWith("net.interface.eth0.config.dhcpClient4.enabled", false); - givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusEnabledLAN"); + givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusManagedLan"); 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", "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); - 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("ipv6", "method", "disabled"); thenResultingBuildAllMapContains("ipv4", "method", "manual"); thenResultingBuildAllMapContains("ipv4", "address-data", buildAddressDataWith("192.168.0.12", new UInt32(25))); - thenResultingBuildAllMapContains("ipv6", "method", "manual"); - thenResultingBuildAllMapContains("ipv6", "address-data", - buildAddressDataWith("fe80::eed:f0a1:d03a:1028", new UInt32(25))); thenResultingBuildAllMapContains("connection", "id", "kura-eth0-connection"); thenResultingBuildAllMapContains("connection", "interface-name", "eth0"); thenResultingBuildAllMapContains("connection", "type", "802-3-ethernet"); @@ -1126,28 +991,20 @@ public void buildSettingsShouldWorkWithExpectedInputsConfiguredForEthernetAndLan @Test public void buildSettingsShouldWorkWithExpectedInputsEthernetAndWan() { givenMapWith("net.interface.eth0.config.dhcpClient4.enabled", false); - givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusEnabledWAN"); + givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusManagedWan"); 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("ipv6", "method", "disabled"); thenResultingBuildAllMapContains("ipv4", "method", "manual"); thenResultingBuildAllMapContains("ipv4", "address-data", buildAddressDataWith("192.168.0.12", new UInt32(25))); - thenResultingBuildAllMapContains("ipv6", "method", "manual"); - thenResultingBuildAllMapContains("ipv6", "address-data", - buildAddressDataWith("fe80::eed:f0a1:d03a:1028", new UInt32(25))); thenResultingBuildAllMapContains("connection", "id", "kura-eth0-connection"); thenResultingBuildAllMapContains("connection", "interface-name", "eth0"); thenResultingBuildAllMapContains("connection", "type", "802-3-ethernet"); @@ -1157,8 +1014,6 @@ public void buildSettingsShouldWorkWithExpectedInputsEthernetAndWan() { public void buildSettingsShouldWorkWithModemSettings() { 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); @@ -1166,8 +1021,8 @@ public void buildSettingsShouldWorkWithModemSettings() { NMDeviceType.NM_DEVICE_TYPE_MODEM); thenNoExceptionsHaveBeenThrown(); + thenResultingBuildAllMapContains("ipv6", "method", "disabled"); thenResultingBuildAllMapContains("ipv4", "method", "auto"); - thenResultingBuildAllMapContains("ipv6", "method", "auto"); thenResultingBuildAllMapContains("connection", "id", "kura-ttyACM0-connection"); thenResultingBuildAllMapContains("connection", "interface-name", "ttyACM0"); thenResultingBuildAllMapContains("connection", "type", "gsm"); @@ -1176,10 +1031,9 @@ public void buildSettingsShouldWorkWithModemSettings() { } @Test - public void buildSettingsShouldThrowWithDhcpDisabledAndNullIp4() { - givenMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusDisabled"); + public void buildSettingsShouldThrowDhcpDisabledAndNullIp() { givenMapWith("net.interface.eth0.config.dhcpClient4.enabled", false); - givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusEnabledWAN"); + givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusManagedWan"); 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"); @@ -1193,27 +1047,9 @@ public void buildSettingsShouldThrowWithDhcpDisabledAndNullIp4() { } @Test - public void buildSettingsShouldThrowDhcpDisabledAndNullIp6() { - 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", "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 buildSettingsShouldThrowDhcpDisabledAndNullPrefixIp4() { - givenMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusDisabled"); + public void buildSettingsShouldThrowDhcpDisabledAndNullPrefix() { givenMapWith("net.interface.eth0.config.dhcpClient4.enabled", false); - givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusEnabledWAN"); + givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusManagedWan"); 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"); @@ -1227,25 +1063,7 @@ public void buildSettingsShouldThrowDhcpDisabledAndNullPrefixIp4() { } @Test - public void buildSettingsShouldThrowDhcpDisabledAndNullPrefixIp6() { - 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", 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 buildSettingsShouldThrowDhcpDisabledAndNullStatusIp4() { - givenMapWith("net.interface.eth0.config.ip6.status", "netIPv6StatusDisabled"); + public void buildSettingsShouldThrowDhcpDisabledAndNullStatus() { 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"); @@ -1261,27 +1079,9 @@ public void buildSettingsShouldThrowDhcpDisabledAndNullStatusIp4() { } @Test - public void buildSettingsShouldThrowDhcpDisabledAndNullStatusIp6() { - givenMapWith("net.interface.eth0.config.ip4.status", "netIPv4StatusDisabled"); - givenMapWith("net.interface.eth0.config.ip6.status", null); - 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); - - thenNoSuchElementExceptionThrown(); - } - - @Test - public void buildSettingsShouldThrowDhcpDisabledAndNullWifiSsidIp4() { - givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusDisabled"); + public void buildSettingsShouldThrowDhcpDisabledAndNullWifiSsid() { givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); - givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusEnabledWAN"); + givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusManagedWan"); 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"); @@ -1305,37 +1105,9 @@ public void buildSettingsShouldThrowDhcpDisabledAndNullWifiSsidIp4() { } @Test - public void buildSettingsShouldThrowDhcpDisabledAndNullWifiSsidIp6() { - givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusDisabled"); - givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusManagedWAN"); - 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 buildSettingsShouldThrowDhcpDisabledAndNullWifiPasswordIp4() { - givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusDisabled"); + public void buildSettingsShouldThrowDhcpDisabledAndNullWifiPassword() { givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); - givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusEnabledWAN"); + givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusManagedWan"); 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"); @@ -1359,37 +1131,9 @@ public void buildSettingsShouldThrowDhcpDisabledAndNullWifiPasswordIp4() { } @Test - public void buildSettingsShouldThrowDhcpDisabledAndNullWifiPasswordIp6() { - givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusDisabled"); - givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusManagedWAN"); - 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 buildSettingsShouldThrowDhcpDisabledAndNullWifiSecurityTypeIp4() { - givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusDisabled"); + public void buildSettingsShouldThrowDhcpDisabledAndNullWifiSecurityType() { givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", false); - givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusEnabledWAN"); + givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusManagedWan"); 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"); @@ -1413,35 +1157,7 @@ public void buildSettingsShouldThrowDhcpDisabledAndNullWifiSecurityTypeIp4() { } @Test - public void buildSettingsShouldThrowDhcpDisabledAndNullWifiSecurityTypeIp6() { - givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusDisabled"); - givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusManagedWAN"); - 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 shouldSupportEmptyWanPriorityPropertyIp4() { - givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusDisabled"); + public void shouldSupportEmptyWanPriorityProperty() { givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", true); givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusEnabledWAN"); givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); @@ -1453,21 +1169,7 @@ public void shouldSupportEmptyWanPriorityPropertyIp4() { } @Test - public void shouldSupportEmptyWanPriorityPropertyIp6() { - givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusDisabled"); - givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledWAN"); - givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodAuto"); - givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); - - whenBuildIpv6SettingsIsRunWith(this.networkProperties, "wlan0"); - - thenNoExceptionsHaveBeenThrown(); - thenResultingMapNotContains("route-metric"); - } - - @Test - public void shouldPopulateWanPriorityPropertyIp4() { - givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusDisabled"); + public void shouldPopulateWanPriorityProperty() { givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", true); givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusEnabledWAN"); givenMapWith("net.interface.wlan0.config.ip4.wan.priority", new Integer(30)); @@ -1480,22 +1182,7 @@ public void shouldPopulateWanPriorityPropertyIp4() { } @Test - public void shouldPopulateWanPriorityPropertyIp6() { - givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusDisabled"); - givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledWAN"); - givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodAuto"); - givenMapWith("net.interface.wlan0.config.ip6.wan.priority", new Integer(30)); - givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); - - whenBuildIpv6SettingsIsRunWith(this.networkProperties, "wlan0"); - - thenNoExceptionsHaveBeenThrown(); - thenResultingMapContains("route-metric", new Variant<>(new Long(30)).getValue()); - } - - @Test - public void shouldNotPopulateWanPriorityPropertyIfNotWANIp4() { - givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusDisabled"); + public void shouldNotPopulateWanPriorityPropertyIfNotWAN() { givenMapWith("net.interface.wlan0.config.dhcpClient4.enabled", true); givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusEnabledLAN"); givenMapWith("net.interface.wlan0.config.ip4.wan.priority", new Integer(30)); @@ -1507,20 +1194,6 @@ public void shouldNotPopulateWanPriorityPropertyIfNotWANIp4() { thenResultingMapNotContains("route-metric"); } - @Test - public void shouldNotPopulateWanPriorityPropertyIfNotWANIp6() { - givenMapWith("net.interface.wlan0.config.ip4.status", "netIPv4StatusDisabled"); - givenMapWith("net.interface.wlan0.config.ip6.status", "netIPv6StatusEnabledLAN"); - givenMapWith("net.interface.wlan0.config.ip6.address.method", "netIPv6MethodAuto"); - givenMapWith("net.interface.wlan0.config.ip6.wan.priority", new Integer(30)); - givenNetworkPropsCreatedWithTheMap(this.internetNetworkPropertiesInstanciationMap); - - whenBuildIpv6SettingsIsRunWith(this.networkProperties, "wlan0"); - - thenNoExceptionsHaveBeenThrown(); - thenResultingMapNotContains("route-metric"); - } - /* * Given */ @@ -1709,4 +1382,4 @@ public Object buildAddressDataWith(String ipAddr, UInt32 prefix) { return dataVariant.getValue(); } -} +} \ No newline at end of file From 812e3dc93e089a6f6e664feeb0f550e3be4ee1f4 Mon Sep 17 00:00:00 2001 From: SimoneFiorani Date: Thu, 27 Jul 2023 14:51:27 +0200 Subject: [PATCH 10/11] refactor(nm): refactor Ip6Privacy --- .../src/main/java/org/eclipse/kura/nm/KuraIp6Privacy.java | 7 +------ .../test/java/org/eclipse/kura/nm/NMDbusConnectorTest.java | 2 +- .../kura/nm/configuration/NMSettingsConverterTest.java | 2 +- 3 files changed, 3 insertions(+), 8 deletions(-) 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 index dc516d638a3..3d90d43b1ef 100644 --- 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 @@ -16,15 +16,12 @@ public enum KuraIp6Privacy { - UNKNOWN, DISABLED, ENABLED_PUBLIC_ADD, ENABLED_TEMP_ADD; public static KuraIp6Privacy fromString(String status) { switch (status) { - case "netIPv6PrivacyUnknown": - return KuraIp6Privacy.UNKNOWN; case "netIPv6PrivacyDisabled": return KuraIp6Privacy.DISABLED; case "netIPv6PrivacyEnabledPubAdd": @@ -38,8 +35,6 @@ public static KuraIp6Privacy fromString(String status) { public static NMSettingIP6ConfigPrivacy toNMSettingIP6ConfigPrivacy(KuraIp6Privacy privacyValue) { switch (privacyValue) { - case UNKNOWN: - return NMSettingIP6ConfigPrivacy.NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN; case DISABLED: return NMSettingIP6ConfigPrivacy.NM_SETTING_IP6_CONFIG_PRIVACY_DISABLED; case ENABLED_PUBLIC_ADD: @@ -47,7 +42,7 @@ public static NMSettingIP6ConfigPrivacy toNMSettingIP6ConfigPrivacy(KuraIp6Priva case ENABLED_TEMP_ADD: return NMSettingIP6ConfigPrivacy.NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR; default: - return NMSettingIP6ConfigPrivacy.NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN; + throw new IllegalArgumentException(String.format("Unsupported IPv6 privacy value: \"%s\"", privacyValue)); } } } diff --git a/kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/NMDbusConnectorTest.java b/kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/NMDbusConnectorTest.java index 0aa7a062eb3..8d45152cd0d 100644 --- a/kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/NMDbusConnectorTest.java +++ b/kura/test/org.eclipse.kura.nm.test/src/test/java/org/eclipse/kura/nm/NMDbusConnectorTest.java @@ -1600,4 +1600,4 @@ private void simulateIwCommandOutputs(String interfaceName, Properties preMocked "/mock/device/" + interfaceName, Wireless.class); } -} \ No newline at end of file +} 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 bbc13544b38..1a8391fdfa3 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 @@ -1382,4 +1382,4 @@ public Object buildAddressDataWith(String ipAddr, UInt32 prefix) { return dataVariant.getValue(); } -} \ No newline at end of file +} From 9f0bc4bd3c67b92ab22798493f9594b95f50f6af Mon Sep 17 00:00:00 2001 From: SimoneFiorani Date: Thu, 27 Jul 2023 17:20:39 +0200 Subject: [PATCH 11/11] test(nm): added full set of unit tests for ipv6 implementation --- .../NMSettingsConverterTest.java | 1344 ++++++++++++++++- 1 file changed, 1321 insertions(+), 23 deletions(-) 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 */