Skip to content

Commit 5a79e37

Browse files
committed
Fixed a couple region codes
Fixed uk-gov-cardiff-1 and sa-vinhedo-1. Added internal regions test.
1 parent afbf7fd commit 5a79e37

File tree

2 files changed

+131
-2
lines changed

2 files changed

+131
-2
lines changed

driver/src/main/java/oracle/nosql/driver/Region.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public class Region {
105105

106106
/* OC4 */
107107
public static final Region UK_GOV_LONDON_1 = new Region("uk-gov-london-1");
108-
public static final Region UK_GOV_CARDIFF_1 = new Region("uk-gov-london-1");
108+
public static final Region UK_GOV_CARDIFF_1 = new Region("uk-gov-cardiff-1");
109109

110110
/* OC8 */
111111
public static final Region AP_CHIYODA_1 = new Region("ap-chiyoda-1");
@@ -119,6 +119,9 @@ public class Region {
119119

120120
static {
121121
/* OC1 */
122+
/* AF */
123+
OC1_REGIONS.put(AF_JOHANNESBURG_1.getRegionId(), AF_JOHANNESBURG_1);
124+
122125
/* APAC */
123126
OC1_REGIONS.put(AP_CHUNCHEON_1.getRegionId(), AP_CHUNCHEON_1);
124127
OC1_REGIONS.put(AP_HYDERABAD_1.getRegionId(), AP_HYDERABAD_1);
@@ -150,7 +153,7 @@ public class Region {
150153
/* LAD */
151154
OC1_REGIONS.put(SA_SAOPAULO_1.getRegionId(), SA_SAOPAULO_1);
152155
OC1_REGIONS.put(SA_SANTIAGO_1.getRegionId(), SA_SANTIAGO_1);
153-
OC1_REGIONS.put(SA_VINHEDO_1.getRegionId(), SA_SANTIAGO_1);
156+
OC1_REGIONS.put(SA_VINHEDO_1.getRegionId(), SA_VINHEDO_1);
154157

155158
/* North America */
156159
OC1_REGIONS.put(US_ASHBURN_1.getRegionId(), US_ASHBURN_1);

driver/src/test/java/oracle/nosql/driver/iam/ConfigFileTest.java

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77

88
package oracle.nosql.driver.iam;
99

10+
import static oracle.nosql.driver.iam.Utils.getIAMURL;
11+
1012
import static org.junit.Assert.assertEquals;
1113
import static org.junit.Assert.assertNotNull;
1214
import static org.junit.Assert.assertNull;
1315
import static org.junit.Assert.fail;
16+
import static org.junit.Assume.assumeTrue;
1417

1518
import java.io.File;
1619
import java.io.FileInputStream;
@@ -21,6 +24,10 @@
2124
import oracle.nosql.driver.NoSQLHandleConfig;
2225
import oracle.nosql.driver.Region;
2326
import oracle.nosql.driver.iam.OCIConfigFileReader.OCIConfigFile;
27+
import oracle.nosql.driver.values.ArrayValue;
28+
import oracle.nosql.driver.values.FieldValue;
29+
import oracle.nosql.driver.values.JsonUtils;
30+
import oracle.nosql.driver.values.MapValue;
2431

2532
import org.junit.After;
2633
import org.junit.Before;
@@ -244,4 +251,123 @@ public void testRegionProvider()
244251
} catch (IllegalArgumentException iae) {
245252
}
246253
}
254+
255+
private MapValue getRealm(ArrayValue realms, String realm) {
256+
for (FieldValue fv : realms) {
257+
MapValue mv = fv.asMap();
258+
String name = mv.get("name").asString().getValue();
259+
if (realm.compareTo(name) == 0) {
260+
return mv;
261+
}
262+
}
263+
return null;
264+
}
265+
266+
private String nosqlEndpoint(ArrayValue realms, MapValue mv) {
267+
String realm = mv.get("realm").asString().getValue();
268+
MapValue realmVals = getRealm(realms, realm);
269+
if (realmVals == null) {
270+
return null;
271+
}
272+
String prefix = realmVals.get("epprefix").asString().getValue();
273+
String suffix = realmVals.get("epsuffix").asString().getValue();
274+
String regionId = mv.get("name").asString().getValue();
275+
return "https://" + prefix + regionId + suffix;
276+
}
277+
278+
private String authEndpoint(ArrayValue realms, MapValue mv) {
279+
String realm = mv.get("realm").asString().getValue();
280+
MapValue realmVals = getRealm(realms, realm);
281+
if (realmVals == null) {
282+
return null;
283+
}
284+
String prefix = realmVals.get("authprefix").asString().getValue();
285+
String suffix = realmVals.get("authsuffix").asString().getValue();
286+
String regionId = mv.get("name").asString().getValue();
287+
return "https://" + prefix + regionId + suffix;
288+
}
289+
290+
291+
@Test
292+
public void testAllRegionCodes() {
293+
/* only execute if we're supplied a path to regions.json file */
294+
String jsonPath = System.getProperty("test.regionsfile");
295+
assumeTrue("Skipping region codes test: no regionsfile given",
296+
(jsonPath != null && !jsonPath.isEmpty()));
297+
MapValue jsonMap = null;
298+
FileInputStream fis = null;
299+
try {
300+
fis = new FileInputStream(jsonPath);
301+
jsonMap = JsonUtils.createValueFromJson(fis, null).asMap();
302+
} catch (Exception e) {
303+
fail("Can't read regions json file '" + jsonPath + "': " + e);
304+
} finally {
305+
if (fis != null) {
306+
try {
307+
fis.close();
308+
} catch (Exception e) {}
309+
}
310+
}
311+
312+
/*
313+
* Regions json has two fields: "realms" and "regions":
314+
* "realms": [
315+
* {
316+
* "name": "oc1",
317+
* "epprefix": "nosql.",
318+
* "epsuffix": ".oci.oraclecloud.com",
319+
* "authprefix": "auth.",
320+
* "authsuffix": ".oraclecloud.com"
321+
* },
322+
* ...]
323+
*
324+
* "regions": [
325+
* {"tlc": "jnb", "realm": "oc1", "name": "af-johannesburg-1"},
326+
* {"tlc": "yny", "realm": "oc1", "name": "ap-chuncheon-1"},
327+
* {"tlc": "nja", "realm": "oc8", "name": "ap-chiyoda-1"},
328+
* ...]
329+
*
330+
* Walk all regions, and verify endpoints for each.
331+
*/
332+
ArrayValue realms = jsonMap.get("realms").asArray();
333+
StringBuilder errs = new StringBuilder();
334+
ArrayValue regions = jsonMap.get("regions").asArray();
335+
for (FieldValue fv : regions) {
336+
MapValue mv = fv.asMap();
337+
String regionId = mv.get("name").asString().getValue();
338+
Region r = Region.fromRegionId(regionId);
339+
if (r == null) {
340+
errs.append(" Missing region '").append(regionId).append("'\n");
341+
} else {
342+
String endpoint = r.endpoint();
343+
String expEndpoint = nosqlEndpoint(realms, mv);
344+
if (expEndpoint.compareTo(endpoint) != 0) {
345+
errs.append(" Wrong nosql endpoint for region '")
346+
.append(regionId).append("':\n")
347+
.append(" expected=").append(expEndpoint).append("\n")
348+
.append(" observed=").append(endpoint).append("\n");
349+
}
350+
}
351+
String expAuthURL = authEndpoint(realms, mv);
352+
353+
String authURL = getIAMURL(regionId);
354+
if (authURL == null || expAuthURL.compareTo(authURL) != 0) {
355+
errs.append(" Wrong auth endpoint for region '")
356+
.append(regionId).append("':\n")
357+
.append(" expected=").append(expAuthURL).append("\n")
358+
.append(" observed=").append(authURL).append("\n");
359+
}
360+
String regionCode = mv.get("tlc").asString().getValue();
361+
authURL = getIAMURL(regionCode);
362+
if (authURL == null ||expAuthURL.compareTo(authURL) != 0) {
363+
errs.append(" Wrong auth endpoint for region code '")
364+
.append(regionCode).append("':\n")
365+
.append(" expected=").append(expAuthURL).append("\n")
366+
.append(" observed=").append(authURL).append("\n");
367+
}
368+
}
369+
if (errs.length() > 0) {
370+
fail("\nErrors found in regions:\n" + errs.toString());
371+
}
372+
}
247373
}

0 commit comments

Comments
 (0)