Skip to content

Commit c5d23fd

Browse files
committed
Implement new CDS changes.
Reflects the libsignal-service-java portion of signalapp/Signal-Android@2791790 - Includes new files that are needed for the change. - Includes random fixes that I ran into
1 parent 21d7c66 commit c5d23fd

30 files changed

+1019
-706
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,62 @@
1-
using libsignalservice.messages.multidevice;
2-
using Microsoft.VisualStudio.TestTools.UnitTesting;
3-
using System;
4-
using System.Collections.Generic;
5-
using System.IO;
6-
using System.Text;
7-
8-
namespace libsignal_service_dotnet_tests
9-
{
10-
[TestClass]
11-
public class ChunkedInputStreamTest
12-
{
13-
[TestMethod]
14-
public void TestReadRawVarint32()
15-
{
16-
MemoryStream ms = new MemoryStream();
17-
byte[] input;
18-
int i;
19-
20-
input = new byte[] { 216, 1, 0, 0, 0, 0, 0,};
21-
ms.Write(input, 0, input.Length);
22-
ms.Position = 0;
23-
24-
i = new ChunkedInputStream(ms).ReadRawVarint32();
25-
ms.Position = 0;
26-
Assert.AreEqual(216, i);
27-
28-
29-
input = new byte[] { 172, 2, 0xff, 0xff, 0, 0, 0, };
30-
ms.Write(input, 0, input.Length);
31-
ms.Position = 0;
32-
33-
i = new ChunkedInputStream(ms).ReadRawVarint32();
34-
ms.Position = 0;
35-
Assert.AreEqual(300, i);
36-
37-
38-
input = new byte[] { 5, 0xff, 0xff, 0xff, 0, 0, 0, };
39-
ms.Write(input, 0, input.Length);
40-
ms.Position = 0;
41-
42-
i = new ChunkedInputStream(ms).ReadRawVarint32();
43-
ms.Position = 0;
44-
Assert.AreEqual(5, i);
45-
46-
47-
input = new byte[] { 199, 232, 67, 0xff, 0, 0, 0, };
48-
ms.Write(input, 0, input.Length);
49-
ms.Position = 0;
50-
51-
i = new ChunkedInputStream(ms).ReadRawVarint32();
52-
ms.Position = 0;
53-
Assert.AreEqual(1111111, i);
54-
55-
56-
input = new byte[] { 128, 1, 0xff, 0xff, 0, 0, 0, };
57-
ms.Write(input, 0, input.Length);
58-
ms.Position = 0;
59-
60-
i = new ChunkedInputStream(ms).ReadRawVarint32();
61-
ms.Position = 0;
62-
Assert.AreEqual(128, i);
63-
}
64-
}
65-
}
1+
using System.IO;
2+
using libsignalservice.messages.multidevice;
3+
using Microsoft.VisualStudio.TestTools.UnitTesting;
4+
5+
namespace libsignal_service_dotnet_tests
6+
{
7+
[TestClass]
8+
public class ChunkedInputStreamTests
9+
{
10+
[TestMethod]
11+
public void TestReadRawVarint32()
12+
{
13+
MemoryStream ms = new MemoryStream();
14+
byte[] input;
15+
int i;
16+
17+
input = new byte[] { 216, 1, 0, 0, 0, 0, 0,};
18+
ms.Write(input, 0, input.Length);
19+
ms.Position = 0;
20+
21+
i = new ChunkedInputStream(ms).ReadRawVarint32();
22+
ms.Position = 0;
23+
Assert.AreEqual(216, i);
24+
25+
26+
input = new byte[] { 172, 2, 0xff, 0xff, 0, 0, 0, };
27+
ms.Write(input, 0, input.Length);
28+
ms.Position = 0;
29+
30+
i = new ChunkedInputStream(ms).ReadRawVarint32();
31+
ms.Position = 0;
32+
Assert.AreEqual(300, i);
33+
34+
35+
input = new byte[] { 5, 0xff, 0xff, 0xff, 0, 0, 0, };
36+
ms.Write(input, 0, input.Length);
37+
ms.Position = 0;
38+
39+
i = new ChunkedInputStream(ms).ReadRawVarint32();
40+
ms.Position = 0;
41+
Assert.AreEqual(5, i);
42+
43+
44+
input = new byte[] { 199, 232, 67, 0xff, 0, 0, 0, };
45+
ms.Write(input, 0, input.Length);
46+
ms.Position = 0;
47+
48+
i = new ChunkedInputStream(ms).ReadRawVarint32();
49+
ms.Position = 0;
50+
Assert.AreEqual(1111111, i);
51+
52+
53+
input = new byte[] { 128, 1, 0xff, 0xff, 0, 0, 0, };
54+
ms.Write(input, 0, input.Length);
55+
ms.Position = 0;
56+
57+
i = new ChunkedInputStream(ms).ReadRawVarint32();
58+
ms.Position = 0;
59+
Assert.AreEqual(128, i);
60+
}
61+
}
62+
}
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,40 @@
1-
using libsignalservice;
2-
using libsignalservice.configuration;
3-
using libsignalservice.push.exceptions;
4-
using libsignalservice.util;
5-
using Microsoft.VisualStudio.TestTools.UnitTesting;
6-
using System;
7-
using System.Collections.Generic;
8-
using System.Net.Http;
9-
using System.Text;
10-
using System.Threading;
11-
using System.Threading.Tasks;
12-
13-
namespace libsignal_service_dotnet_tests
14-
{
15-
[TestClass]
16-
public class ConnectionTest
17-
{
18-
public static SignalServiceUrl[] ServiceUrls = new SignalServiceUrl[] { new SignalServiceUrl("https://textsecure-service.whispersystems.org") };
19-
public static SignalContactDiscoveryUrl[] ContactDiscoveryUrls = new SignalContactDiscoveryUrl[] { new SignalContactDiscoveryUrl("https://api.directory.signal.org") };
20-
public static SignalServiceConfiguration ServiceConfiguration = new SignalServiceConfiguration(ServiceUrls, null, ContactDiscoveryUrls);
21-
public static string UserAgent = "libsignal-service-dotnet-tests";
22-
23-
[TestMethod]
24-
public async Task TestConnection()
25-
{
26-
var cancelSource = new CancellationTokenSource();
27-
var pushServiceSocket = new SignalServiceAccountManager(ServiceConfiguration, "A", "B", 1, UserAgent);
28-
try
29-
{
30-
var turn = await pushServiceSocket.GetTurnServerInfo(cancelSource.Token);
31-
}
32-
catch (AuthorizationFailedException) { }
33-
}
34-
35-
[TestMethod]
36-
public async Task TestSignalConnections()
37-
{
38-
using HttpClient httpClient = Util.CreateHttpClient();
39-
await httpClient.GetAsync(ServiceUrls[0].Url);
40-
await httpClient.GetAsync(ContactDiscoveryUrls[0].Url);
41-
}
42-
}
43-
}
1+
using System.Net.Http;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using libsignalservice;
5+
using libsignalservice.configuration;
6+
using libsignalservice.push.exceptions;
7+
using libsignalservice.util;
8+
using Microsoft.VisualStudio.TestTools.UnitTesting;
9+
10+
namespace libsignal_service_dotnet_tests
11+
{
12+
[TestClass]
13+
public class ConnectionTests
14+
{
15+
public static SignalServiceUrl[] ServiceUrls = new SignalServiceUrl[] { new SignalServiceUrl("https://textsecure-service.whispersystems.org") };
16+
public static SignalContactDiscoveryUrl[] ContactDiscoveryUrls = new SignalContactDiscoveryUrl[] { new SignalContactDiscoveryUrl("https://api.directory.signal.org") };
17+
public static SignalServiceConfiguration ServiceConfiguration = new SignalServiceConfiguration(ServiceUrls, null, ContactDiscoveryUrls);
18+
public static string UserAgent = "libsignal-service-dotnet-tests";
19+
20+
[TestMethod]
21+
public async Task TestConnection()
22+
{
23+
var cancelSource = new CancellationTokenSource();
24+
var pushServiceSocket = new SignalServiceAccountManager(ServiceConfiguration, "A", "B", 1, UserAgent, Util.CreateHttpClient());
25+
try
26+
{
27+
var turn = await pushServiceSocket.GetTurnServerInfo(cancelSource.Token);
28+
}
29+
catch (AuthorizationFailedException) { }
30+
}
31+
32+
[TestMethod]
33+
public async Task TestSignalConnections()
34+
{
35+
using HttpClient httpClient = Util.CreateHttpClient();
36+
await httpClient.GetAsync(ServiceUrls[0].Url);
37+
await httpClient.GetAsync(ContactDiscoveryUrls[0].Url);
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)