public async Task OTAA_Join_With_Wrong_AppKey_Fails() { var device = TestFixtureCi.Device3_OTAA; LogTestStart(device); var appKeyToUse = AppKey.Parse("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); Assert.NotEqual(appKeyToUse, device.AppKey); await ArduinoDevice.setDeviceModeAsync(LoRaArduinoSerial._device_mode_t.LWOTAA); await ArduinoDevice.setIdAsync(device.DevAddr, device.DeviceID, device.AppEui); await ArduinoDevice.setKeyAsync(device.NwkSKey, device.AppSKey, appKeyToUse); await ArduinoDevice.SetupLora(TestFixtureCi.Configuration); var joinSucceeded = await ArduinoDevice.setOTAAJoinAsyncWithRetry(LoRaArduinoSerial._otaa_join_cmd_t.JOIN, 20000, 3); Assert.False(joinSucceeded, "Join suceeded for invalid AppKey (mic check should fail)"); await TestFixtureCi.AssertNetworkServerModuleLogStartsWithAsync( $"{device.DeviceID}: join refused: invalid MIC", $"{device.DeviceID}: join request MIC invalid"); await ArduinoDevice.WaitForIdleAsync(); }
private AppKey GetAppKey(int value) => AppKey.Parse(GetKeyString(value));
public static bool TryRead <T>(this TwinCollection twinCollection, string property, ILogger?logger, [NotNullWhen(true)] out T?value) { _ = twinCollection ?? throw new ArgumentNullException(nameof(twinCollection)); value = default; if (!twinCollection.Contains(property)) { return(false); } // cast to object to avoid dynamic code to be generated var some = (object)twinCollection[property]; // quick path for values that can be directly converted if (some is Newtonsoft.Json.Linq.JValue someJValue) { if (someJValue.Value is T someT) { value = someT; return(true); } } try { var t = typeof(T); var tPrime = Nullable.GetUnderlyingType(t) ?? t; // For 100% case coverage we should handle the case where type T is nullable and the token is null. // Since this is not possible in IoT hub, we do not handle the null cases exhaustively. if (tPrime == StationEuiType) { value = (T)(object)StationEui.Parse(some.ToString()); } else if (tPrime == DevNonceType) { value = (T)(object)new DevNonce(Convert.ToUInt16(some, CultureInfo.InvariantCulture)); } else if (tPrime == DevAddrType) { value = (T)(object)DevAddr.Parse(some.ToString()); } else if (tPrime == AppSessionKeyType) { value = (T)(object)AppSessionKey.Parse(some.ToString()); } else if (tPrime == AppKeyType) { value = (T)(object)AppKey.Parse(some.ToString()); } else if (tPrime == NetworkSessionKeyType) { value = (T)(object)NetworkSessionKey.Parse(some.ToString()); } else if (tPrime == JoinEuiType) { value = (T)(object)JoinEui.Parse(some.ToString()); } else if (tPrime == NetIdType) { value = (T)(object)NetId.Parse(some.ToString()); } else { value = (T)Convert.ChangeType(some, t, CultureInfo.InvariantCulture); } if (t.IsEnum && !t.IsEnumDefined(value)) { LogParsingError(logger, property, some); return(false); } } catch (Exception ex) when(ex is ArgumentException or InvalidCastException or FormatException or OverflowException or Newtonsoft.Json.JsonSerializationException) { LogParsingError(logger, property, some, ex); return(false); } return(true); }
public AppKey GetAppKey(int deviceId, bool multiGw = false) => AppKey.Parse(GetKey32(deviceId, multiGw));
public void Parse_Throws_When_Input_Is_Invalid() { _ = Assert.Throws <FormatException>(() => AppKey.Parse("foobar")); }