-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add syncupdate support for apikey (#1626)
* add syncupdate support for apikey * refactor * fix build * add tests --------- Co-authored-by: Ed Shryane <[email protected]>
- Loading branch information
1 parent
85a6e83
commit fcd55cc
Showing
4 changed files
with
106 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
import net.ripe.db.whois.api.rest.domain.WhoisResources; | ||
import net.ripe.db.whois.api.rest.mapper.FormattedClientAttributeMapper; | ||
import net.ripe.db.whois.api.rest.mapper.WhoisObjectMapper; | ||
import net.ripe.db.whois.api.syncupdate.SyncUpdateUtils; | ||
import net.ripe.db.whois.common.apiKey.ApiKeyUtils; | ||
import net.ripe.db.whois.common.rpsl.AttributeType; | ||
import net.ripe.db.whois.common.rpsl.RpslAttribute; | ||
|
@@ -193,6 +194,64 @@ public void request_failed_with_basic_auth_api_key_illegal_bearer_header() { | |
assertThat(response.getStatus(), is(HttpStatus.BAD_REQUEST_400)); | ||
} | ||
|
||
@Test | ||
public void update_selfrefencing_maintainer_only_data_parameter_with_api_key() { | ||
final String mntner = | ||
"mntner: SSO-MNT\n" + | ||
"descr: description\n" + | ||
"admin-c: TP1-TEST\n" + | ||
"upd-to: [email protected]\n" + | ||
"auth: SSO [email protected]\n" + | ||
"mnt-by: SSO-MNT\n" + | ||
"source: TEST"; | ||
databaseHelper.addObject(mntner); | ||
|
||
final String response = SecureRestTest.target(getSecurePort(), "whois/syncupdates/test?" + | ||
"DATA=" + SyncUpdateUtils.encode(mntner + "\nremarks: updated")) | ||
.request() | ||
.header(HttpHeaders.AUTHORIZATION, getBasicAuthHeader(BASIC_AUTH_PERSON_NO_MNT)) | ||
.get(String.class); | ||
|
||
assertThat(response, containsString("Modify SUCCEEDED: [mntner] SSO-MNT")); | ||
} | ||
|
||
@Test | ||
public void create_mntner_only_data_parameter_with_apiKey() { | ||
final String mntner = | ||
"mntner: SSO-MNT\n" + | ||
"descr: description\n" + | ||
"admin-c: TP1-TEST\n" + | ||
"upd-to: [email protected]\n" + | ||
"auth: SSO [email protected]\n" + | ||
"mnt-by: SSO-MNT\n" + | ||
"source: TEST"; | ||
|
||
final String response = SecureRestTest.target(getSecurePort(), "whois/syncupdates/test?" + "DATA=" + SyncUpdateUtils.encode(mntner)) | ||
.request() | ||
.header(HttpHeaders.AUTHORIZATION, getBasicAuthHeader(BASIC_AUTH_PERSON_NO_MNT)) | ||
.get(String.class); | ||
|
||
assertThat(response, containsString("Create SUCCEEDED: [mntner] SSO-MNT")); | ||
} | ||
|
||
@Test | ||
public void create_mntner_only_data_parameter_with_apiKey_fails_no_sso() { | ||
final String mntner = | ||
"mntner: SSO-MNT\n" + | ||
"descr: description\n" + | ||
"admin-c: TP1-TEST\n" + | ||
"upd-to: [email protected]\n" + | ||
"auth: SSO [email protected]\n" + | ||
"mnt-by: SSO-MNT\n" + | ||
"source: TEST"; | ||
|
||
final String response = SecureRestTest.target(getSecurePort(), "whois/syncupdates/test?" + "DATA=" + SyncUpdateUtils.encode(mntner)) | ||
.request() | ||
.header(HttpHeaders.AUTHORIZATION, getBasicAuthHeader(BASIC_AUTH_TEST_TEST_MNT)) | ||
.get(String.class); | ||
|
||
assertThat(response, containsString("Create FAILED: [mntner] SSO-MNT")); | ||
} | ||
|
||
@Test | ||
public void lookup_correct_api_key_with_sso_and_unfiltered() { | ||
|
@@ -772,7 +831,7 @@ private WhoisResources map(final RpslObject ... rpslObjects) { | |
return whoisObjectMapper.mapRpslObjects(FormattedClientAttributeMapper.class, rpslObjects); | ||
} | ||
|
||
private static String getBasicAuthHeader(final String basicAuth) { | ||
public static String getBasicAuthHeader(final String basicAuth) { | ||
return StringUtils.joinWith(" ","Basic ", basicAuth); | ||
} | ||
|
||
|