Version 3.0.361

This commit is contained in:
Anja 2023-03-08 13:18:54 +01:00
parent faf68061f4
commit cba4da9357
88 changed files with 1119 additions and 1502 deletions

View file

@ -0,0 +1,85 @@
using System.Linq;
using System.Text;
using NUnit.Framework;
using TINK.Services.BluetoothLock.Crypto;
namespace TestTINKLib.Fixtures.ObjectTests.Services.BluetoothLock.Crypto
{
[TestFixture]
public class TestCryptoHelper
{
/// <summary>
/// Ensures that decyption from haveltec- lib produces the same results than sharee lib.
/// </summary>
[Test]
public void Test_DecryptStringFromBytes_Aes()
{
// keyCopri (value copied from debugging session of sharing_ble_lib/ haveltec code)
var keyCopri = (new sbyte[] { -6, 53, 29, -112, 7, -83, -41, -7, 30, 45, -13, -2, -108, -29, -90, 71, 15, -74, -76, 32, 0, 0, 0, 0 }).Select(x => (byte)x).ToArray();
// Encrypted seed value from lock (value copied from debugging session of sharing_ble_lib/ haveltec code)
var seedLockEnc = (new sbyte[] { 50, 51, -40, 64, 42, 82, 97, -24, 20, -39, -15, 126, 119, -110, 47, -18 }).Select(x => (byte)x).ToArray();
// Decrypted seed value from lock (value copied from debugging session of sharing_ble_lib/ haveltec code)
var acces_key = (new sbyte[] { 19, -66, 55, 18, -106, -92, 70, -40, 117, -87, -19, 124, 19, 54, -18, -82 }).Select(x => (byte)x).ToArray();
var decrypt = new Cipher().Decrypt(keyCopri, seedLockEnc);
Assert.IsTrue(acces_key.SequenceEqual(decrypt));
}
[Test]
public void TestGetSeedLock()
{
// seed copri (value copied from debugging session of sharing_ble_lib/ haveltec code)
byte[] seedCopri = (new sbyte[] { -7, -69, 16, -52, 88, 38, -92, 82, -99, -79, 19, 16, -41, -127, 51, 24 }).Select(x => (byte)x).ToArray();
// keyCopri (value copied from debugging session of sharing_ble_lib/ haveltec code)
byte[] keyCopri = (new sbyte[] { -6, 53, 29, -112, 7, -83, -41, -7, 30, 45, -13, -2, -108, -29, -90, 71, 15, -74, -76, 32, 0, 0, 0, 0 }).Select(x => (byte)x).ToArray();
// Encrypted seed value from lock (value copied from debugging session of sharing_ble_lib/ haveltec code)
byte[] seedLockEnc = (new sbyte[] { 92, 80, -36, -2, 101, -31, -23, -43, 71, 62, 126, -70, 54, -53, -119, -56 }).Select(x => (byte)x).ToArray();
//// Decryped seed value? access values? from lock (value copied from debugging session of sharing_ble_lib/ haveltec code)
byte[] seedLockDec = (new sbyte[] { 62, -51, 96, -80, 7, -84, 48, -104, 47, 51, -22, -23, 30, -10, -88, -97 }).Select(x => (byte)x).ToArray();
var crypto = new AuthCryptoHelper(
seedLockEnc,
keyCopri,
null);
var result = crypto.GetSeedLock();
Assert.IsTrue(seedLockDec.SequenceEqual(result));
}
[Test]
public void TestGetAccessKeyEncrypted()
{
// seed copri (value copied from debugging session of sharing_ble_lib/ haveltec code)
byte[] seedCopri = (new sbyte[] { -7, -69, 16, -52, 88, 38, -92, 82, -99, -79, 19, 16, -41, -127, 51, 24 }).Select(x => (byte)x).ToArray();
// keyCopri (value copied from debugging session of sharing_ble_lib/ haveltec code)
byte[] keyCopri = (new sbyte[] { -6, 53, 29, -112, 7, -83, -41, -7, 30, 45, -13, -2, -108, -29, -90, 71, 15, -74, -76, 32, 0, 0, 0, 0 }).Select(x => (byte)x).ToArray();
// Encrypted seed value from lock (value copied from debugging session of sharing_ble_lib/ haveltec code)
byte[] seedLockEnc = (new sbyte[] { 92, 80, -36, -2, 101, -31, -23, -43, 71, 62, 126, -70, 54, -53, -119, -56 }).Select(x => (byte)x).ToArray();
// Decryped seed value? access values? from lock (value copied from debugging session of sharing_ble_lib/ haveltec code)
byte[] seedLockDec = (new sbyte[] { 62, -51, 96, -80, 7, -84, 48, -104, 47, 51, -22, -23, 30, -10, -88, -97 }).Select(x => (byte)x).ToArray();
var crypto = new AuthCryptoHelper(
seedLockEnc,
keyCopri,
null);
var result = crypto.GetSeedLock();
Assert.AreEqual(
Encoding.UTF8.GetString(seedLockDec),
Encoding.UTF8.GetString(result));
}
}
}

View file

@ -0,0 +1,24 @@
using NUnit.Framework;
using TINK.Services.BluetoothLock.Tdo;
namespace TestTINKLib.Fixtures.ObjectTests.Services.BluetoothLock.Tdo
{
[TestFixture]
public class TestLockInfoAuthTdo
{
[Test]
public void TestCtor()
{
var auth = new LockInfoAuthTdo.Builder
{
K_seed = null,
K_u = null,
K_a = null,
}.Build();
Assert.That(auth.K_seed, Is.Not.Null);
Assert.That(auth.K_u, Is.Not.Null);
Assert.That(auth.K_a, Is.Not.Null);
}
}
}

View file

@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using TINK.Model.Bikes;
using TINK.Model.Bikes.BikeInfoNS.BikeNS;
using TINK.Model.Bikes.BikeInfoNS.DriveNS;
using TINK.Services.BluetoothLock;
using TINK.Services.BluetoothLock.Tdo;
namespace TestTINKLib.Fixtures.ObjectTests.Service.LockService
{
[TestFixture]
public class TestLockServiceSimulation
{
[Test]
public void TestUpdateSimulationInstance_Update()
{
var service = new LocksServiceInReach();
var bikes = new BikeCollection(new Dictionary<string, TINK.Model.Bikes.BikeInfoNS.BC.BikeInfo>()
{
{ "42", new TINK.Model.Bikes.BikeInfoNS.BluetoothLock.BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("42", LockModel.ILockIt), new Drive(), TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri, 1, new Guid(),new byte[] { 1, 4 }, new byte[] { 3, 4 }, new byte[] { 3, 4 }, DateTime.Now, "a@b", "1" , null /*operator uri*/) },
{ "43", new TINK.Model.Bikes.BikeInfoNS.BluetoothLock.BikeInfo(new TINK.Model.Bikes.BikeInfoNS.BikeNS.Bike("43", LockModel.ILockIt), new Drive(), TINK.Model.Bikes.BikeInfoNS.BC.DataSource.Copri, 3, new Guid(),new byte[] { 4, 4 }, new byte[] { 4, 7 }, new byte[] { 5, 4 }, DateTime.Now, "c@b", "1" , null /*operator uri*/) }
}
);
if (service is ILocksServiceFake serviceFake)
{
serviceFake.UpdateSimulation(bikes);
}
Assert.AreEqual(2, service.GetLocksStateAsync(new List<LockInfoAuthTdo>(), new TimeSpan(0, 0, 3)).Result.Count());
}
}
}

View file

@ -0,0 +1,26 @@
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using TINK.Model.Device;
using TINK.Services.BluetoothLock;
namespace TestTINKLib.Fixtures.ObjectTests.Services
{
[TestFixture]
public class TestLocksServicesContainerMutable
{
[Test]
public void TestCtorCustomServices()
{
var ciper = NSubstitute.Substitute.For<ICipher>();
var firstService = NSubstitute.Substitute.For<ILocksService>();
Assert.That(
new LocksServicesContainerMutable(
firstService.GetType().FullName,
new HashSet<ILocksService>() { firstService }
).Count,
Is.EqualTo(1));
}
}
}

View file

@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;
using TINK.Model.Services.CopriApi.ServerUris;
namespace TestTINKLib.Fixtures.ObjectTests.Connector
{
[TestFixture]
public class TestCopriServerUriList
{
[Test]
public void TestConstruct()
{
var l_oUri = new CopriServerUriList();
Assert.Greater(l_oUri.Uris.Count, 0, "There must be at least one uri");
Assert.NotNull(l_oUri.ActiveUri);
}
[Test]
public void TestConstruct_AryStringString()
{
var l_oUri = new CopriServerUriList(
(new List<Uri> { new Uri("http://1.2.3.4"), new Uri("http://2.3.4.5"), new Uri("http://3.4.5.6") }).ToArray(),
new Uri("http://2.3.4.5"));
Assert.AreEqual(3, l_oUri.Uris.Count);
Assert.AreEqual(new Uri("http://2.3.4.5"), l_oUri.ActiveUri);
}
[Test]
public void TestConstruct_AryStringString_NullList()
{
Assert.Throws<ArgumentException>(() => new CopriServerUriList(
null,
new Uri("http://2.3.4.5")));
}
[Test]
public void TestConstruct_AryStringString_InvalidList()
{
Assert.Throws<ArgumentException>(() => new CopriServerUriList(
(new List<Uri>()).ToArray(),
new Uri("http://2.3.4.5")));
}
[Test]
public void TestConstruct_AryStringString_InvalidActiveUri()
{
Assert.Throws<ArgumentException>(() => new CopriServerUriList(
(new List<Uri> { new Uri("http://1.2.3.4"), new Uri("http://2.3.4.5"), new Uri("http://3.4.5.6") }).ToArray(),
new Uri("http://9.9.9.9")));
}
[Test]
public void TestDefaultActiveUri()
{
Assert.AreEqual(
"https://shareeapp-primary.copri.eu/APIjsonserver",
CopriServerUriList.DefaultActiveUri.AbsoluteUri,
"In production environment, server address must always be app.tink-konstanz.de/APIjsonserver.");
}
}
}