use of net.ripe.rpki.validator3.api.trustanchors.TrustAnchorResource in project rpki-validator-3 by RIPE-NCC.
the class TrustAnchorControllerTest method should_fail_on_invalid_request.
@Test
public void should_fail_on_invalid_request() throws Exception {
ResultActions result = mvc.perform(post("/api/trust-anchors").accept(Api.API_MIME_TYPE).contentType(Api.API_MIME_TYPE).content(objectMapper.writeValueAsString(ApiCommand.of(AddTrustAnchor.builder().type(TrustAnchor.TYPE).name(TEST_CA_NAME).locations(Arrays.asList("invalid-location")).subjectPublicKeyInfo("public key info too short").build()))));
result.andExpect(status().isBadRequest()).andExpect(content().contentType(Api.API_MIME_TYPE));
ApiResponse<TrustAnchorResource> response = addTrustAnchorResponse(result);
assertThat(response.getErrors()).isNotEmpty();
}
use of net.ripe.rpki.validator3.api.trustanchors.TrustAnchorResource in project rpki-validator-3 by RIPE-NCC.
the class TrustAnchorControllerTest method should_add_trust_anchor.
@Test
public void should_add_trust_anchor() throws Exception {
ResultActions result = mvc.perform(post("/api/trust-anchors").accept(Api.API_MIME_TYPE).contentType(Api.API_MIME_TYPE).content(objectMapper.writeValueAsString(ApiCommand.of(AddTrustAnchor.builder().type(TrustAnchor.TYPE).name(TEST_CA_NAME).locations(Arrays.asList("rsync://example.com/rpki")).subjectPublicKeyInfo("jdfakljkldf;adsfjkdsfkl;nasdjfnsldajfklsd;ajfk;ljdsakjfkla;sdhfkjdshfkljadsl;kjfdklfjdaksl;jdfkl;jafkldjsfkl;adjsfkl;adjsf;lkjkl;dj;adskjfdljadjbkfbkjblafkjdfbasfjlka").build()))));
result.andExpect(status().isCreated()).andExpect(content().contentType(Api.API_MIME_TYPE));
ApiResponse<TrustAnchorResource> response = addTrustAnchorResponse(result);
assertThat(response.getData()).isNotNull();
TrustAnchorResource resource = response.getData();
Link selfRel = resource.getLinks().getLink("self");
mvc.perform(get(selfRel.getHref()).accept(Api.API_MIME_TYPE)).andExpect(status().isOk()).andExpect(content().contentType(Api.API_MIME_TYPE)).andExpect(jsonPath("$.data.name").value(TEST_CA_NAME));
}
use of net.ripe.rpki.validator3.api.trustanchors.TrustAnchorResource in project rpki-validator-3 by RIPE-NCC.
the class TrustAnchorController method add.
@PostMapping(path = "/upload", consumes = "multipart/form-data")
public ResponseEntity<ApiResponse<TrustAnchorResource>> add(@RequestParam("file") MultipartFile trustAnchorLocator, Locale locale) {
try {
TrustAnchorLocator locator = TrustAnchorLocator.fromMultipartFile(trustAnchorLocator);
AddTrustAnchor command = AddTrustAnchor.builder().type(TrustAnchor.TYPE).name(locator.getCaName()).locations(locator.getCertificateLocations().stream().map(URI::toASCIIString).collect(Collectors.toList())).subjectPublicKeyInfo(locator.getPublicKeyInfo()).rsyncPrefetchUri(locator.getPrefetchUris().stream().filter(uri -> "rsync".equalsIgnoreCase(uri.getScheme())).map(URI::toASCIIString).findFirst().orElse(null)).build();
long id = trustAnchorService.execute(command);
TrustAnchor trustAnchor = trustAnchorRepository.get(id);
Link selfRel = linkTo(methodOn(TrustAnchorController.class).get(id, locale)).withSelfRel();
return ResponseEntity.created(URI.create(selfRel.getHref())).body(trustAnchorResource(trustAnchor, locale));
} catch (TrustAnchorExtractorException ex) {
return ResponseEntity.badRequest().body(ApiResponse.error(ApiError.of(HttpStatus.BAD_REQUEST, "Invalid trust anchor locator: " + ex.getMessage())));
}
}
use of net.ripe.rpki.validator3.api.trustanchors.TrustAnchorResource in project rpki-validator-3 by RIPE-NCC.
the class ObjectController method list.
@GetMapping(path = "/validated")
public ResponseEntity<ApiResponse<ValidatedObjects>> list(Locale locale) {
final Map<Long, TrustAnchorResource> trustAnchorsById = trustAnchors.findAll().stream().collect(Collectors.toMap(TrustAnchor::getId, ta -> TrustAnchorResource.of(ta, locale)));
final Map<Long, Links> trustAnchorLinks = trustAnchorsById.entrySet().stream().collect(Collectors.toMap(entry -> entry.getKey(), entry -> new Links(entry.getValue().getLinks().getLink("self").withRel(TrustAnchor.TYPE))));
final Stream<RoaPrefix> validatedPrefixes = validatedRpkiObjects.findCurrentlyValidatedRoaPrefixes(null, null, null).getObjects().filter(new IgnoreFiltersPredicate(ignoreFilters.all()).negate()).map(prefix -> {
Links links = trustAnchorLinks.get(prefix.getTrustAnchor().getId());
return new RoaPrefix(String.valueOf(prefix.getAsn()), prefix.getPrefix().toString(), prefix.getEffectiveLength(), links);
});
final Stream<RoaPrefix> assertions = roaPrefixAssertions.all().map(assertion -> new RoaPrefix(new Asn(assertion.getAsn()).toString(), IpRange.parse(assertion.getPrefix()).toString(), assertion.getMaximumLength() != null ? assertion.getMaximumLength() : IpRange.parse(assertion.getPrefix()).getPrefixLength(), null));
final Stream<RoaPrefix> combinedPrefixes = Stream.concat(validatedPrefixes, assertions).distinct();
final Stream<ValidatedRpkiObjects.RouterCertificate> certificates = validatedRpkiObjects.findCurrentlyValidatedRouterCertificates().getObjects();
final Stream<RouterCertificate> filteredRouterCertificates = bgpSecFilterService.filterCertificates(certificates).map(o -> new RouterCertificate(o.getAsn(), o.getSubjectKeyIdentifier(), o.getSubjectPublicKeyInfo()));
final Stream<RouterCertificate> bgpSecAssertions = this.bgpSecAssertions.all().map(b -> {
final List<String> asns = Collections.singletonList(String.valueOf(b.getAsn()));
return new RouterCertificate(asns, b.getSki(), b.getPublicKey());
});
final Stream<RouterCertificate> combinedAssertions = Stream.concat(filteredRouterCertificates, bgpSecAssertions).distinct();
return ResponseEntity.ok(ApiResponse.<ValidatedObjects>builder().data(new ValidatedObjects(settings.isInitialValidationRunCompleted(), trustAnchorsById.values(), combinedPrefixes, combinedAssertions)).build());
}
use of net.ripe.rpki.validator3.api.trustanchors.TrustAnchorResource in project rpki-validator-3 by RIPE-NCC.
the class TrustAnchorController method add.
@PostMapping(consumes = { Api.API_MIME_TYPE, "application/json" })
public ResponseEntity<ApiResponse<TrustAnchorResource>> add(@RequestBody @Valid ApiCommand<AddTrustAnchor> command, Locale locale) {
long id = trustAnchorService.execute(command.getData());
TrustAnchor trustAnchor = trustAnchorRepository.get(id);
Link selfRel = linkTo(methodOn(TrustAnchorController.class).get(id, locale)).withSelfRel();
return ResponseEntity.created(URI.create(selfRel.getHref())).body(trustAnchorResource(trustAnchor, locale));
}
Aggregations