Skip to content

Commit f86772a

Browse files
committed
allow multiple IPs in config [#17]
1 parent 4362799 commit f86772a

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

BunqSdk.Tests/BunqSdkTestBase.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class BunqSdkTestBase
2424
/// Configuration items.
2525
/// </summary>
2626
private static readonly string API_KEY = Config.GetApiKey();
27-
private static readonly string FIELD_PERMITTED_IP = Config.GetPermittedIp();
27+
private static readonly string[] FIELD_PERMITTED_IPS = Config.GetPermittedIps();
2828

2929
/// <summary>
3030
/// Gets an Api Context, re-creates if needed and returns it.
@@ -54,9 +54,8 @@ protected static ApiContext GetApiContext()
5454

5555
private static ApiContext CreateApiContext()
5656
{
57-
var permittedIps = new List<string> {FIELD_PERMITTED_IP};
58-
59-
return ApiContext.Create(ApiEnvironmentType.SANDBOX, API_KEY, DEVICE_DESCRIPTION_TEST, permittedIps);
57+
return ApiContext.Create(ApiEnvironmentType.SANDBOX, API_KEY, DEVICE_DESCRIPTION_TEST,
58+
new List<string>(FIELD_PERMITTED_IPS));
6059
}
6160
}
6261
}

BunqSdk.Tests/Config.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
1-
using System.IO;
1+
using System.Collections.Immutable;
2+
using System.IO;
23
using Bunq.Sdk.Model.Generated.Object;
34
using Newtonsoft.Json.Linq;
45

56
namespace Bunq.Sdk.Tests
67
{
78
public class Config
89
{
10+
/// <summary>
11+
/// Delimiter between the IP addresses in the PERMITTED_IPS field.
12+
/// </summary>
13+
private const char DELIMITER_IPS = ',';
14+
15+
/// <summary>
16+
/// Length of an empty array.
17+
/// </summary>
18+
private const int LENGTH_NONE = 0;
19+
20+
/// <summary>
21+
/// Field constants.
22+
/// </summary>
923
private const string FIELD_CONFIG_FILE_PATH = "../../../Resources/config.json";
1024
private const string FIELD_USER_ID = "USER_ID";
1125
private const string FIELD_API_KEY = "API_KEY";
12-
private const string FIELD_PERMITTED_IP = "ipAddress";
26+
private const string FIELD_PERMITTED_IPS = "PERMITTED_IPS";
1327
private const string FIELD_ATTACHMENT_PUBLIC_TEST = "AttachmentPublicTest";
1428
private const string FIELD_ATTACHMENT_PATH_IN = "PATH_IN";
1529
private const string FIELD_ATTACHMENT_DESCRIPTION = "DESCRIPTION";
@@ -69,9 +83,13 @@ public static string GetAttachmentContentType()
6983
return GetConfig()[FIELD_ATTACHMENT_PUBLIC_TEST][FIELD_ATTACHMENT_CONTENT_TYPE].ToString();
7084
}
7185

72-
public static string GetPermittedIp()
86+
public static string[] GetPermittedIps()
7387
{
74-
return GetConfig()[FIELD_PERMITTED_IP].ToString();
88+
var permittedIpsString = GetConfig()[FIELD_PERMITTED_IPS].ToString();
89+
90+
return permittedIpsString.Length == LENGTH_NONE ?
91+
new string[LENGTH_NONE] :
92+
permittedIpsString.Split(DELIMITER_IPS);
7593
}
7694

7795
public static string GetApiKey()

BunqSdk.Tests/Resources/config.example.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"USER_ID": "XXXX",
44
"MONETARY_ACCOUNT_ID": "XXXX",
55
"MONETARY_ACCOUNT_ID2": "XXXX",
6-
"ipAddress": "<ip address>",
6+
"PERMITTED_IPS": "<ip address>,<another ip address>",
77
"AttachmentPublicTest": {
88
"CONTENT_TYPE": "image/png",
99
"DESCRIPTION": "TEST PNG PHP",

0 commit comments

Comments
 (0)