Skip to content

Commit

Permalink
Merge pull request #1582 from webauthn4j/dependabot/gradle/webauthn4j…
Browse files Browse the repository at this point in the history
…Version-0.28.4.RELEASE

chore(deps): bump webauthn4jVersion from 0.28.3.RELEASE to 0.28.4.RELEASE
  • Loading branch information
github-actions[bot] authored Jan 1, 2025
2 parents 9f3a7d5 + 58a47b1 commit 50fd34b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ buildscript {
asciidoctorGradleVersion = "4.0.4"

//Libraries
webauthn4jVersion = '0.28.3.RELEASE'
webauthn4jVersion = '0.28.4.RELEASE'
springSecurityVersion = '6.0.2'

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,17 @@
package com.webauthn4j.springframework.security.metadata;

import com.webauthn4j.metadata.HttpClient;
import com.webauthn4j.metadata.exception.MDSException;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.util.Assert;
import org.springframework.web.client.RestTemplate;

import java.io.IOException;
import java.util.Objects;

/**
* An {@link HttpClient} implementation with Spring {@link RestTemplate}
*/
Expand All @@ -36,7 +44,13 @@ public RestTemplateAdaptorHttpClient(RestTemplate restTemplate) {
* {@inheritDoc}
*/
@Override
public String fetch(String url) {
return restTemplate.getForObject(url, String.class);
public Response fetch(String url) {
ResponseEntity<Resource> entity = restTemplate.getForEntity(url, Resource.class);
Resource resource = Objects.requireNonNull(entity.getBody());
try {
return new Response(entity.getStatusCode().value(), resource.getInputStream());
} catch (IOException e) {
throw new MDSException("Failed to fetch " + url, e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,55 @@


import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.client.RestClientTest;
import org.springframework.boot.test.context.TestComponent;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.client.MockRestServiceServer;
import org.springframework.web.client.RestTemplate;

import java.io.IOException;

import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;

@RunWith(MockitoJUnitRunner.class)
public class RestTemplateAdaptorHttpClientTest {

@Mock
private RestTemplate restTemplate;

@Mock
ResponseEntity<Resource> entity;

@Mock
Resource resource;

@Test
public void fetch_test() {
public void fetch_test() throws IOException {
String url = "https://example.com/webauthn/options";
RestTemplate restTemplate = mock(RestTemplate.class);
when(restTemplate.getForObject(eq(url), eq(String.class))).thenReturn("response");
when(restTemplate.getForEntity(eq(url), eq(Resource.class))).thenReturn(entity);
when(entity.getBody()).thenReturn(resource);
when(entity.getStatusCode()).thenReturn(HttpStatusCode.valueOf(200));
when(resource.getInputStream()).thenReturn(null);
RestTemplateAdaptorHttpClient httpClient = new RestTemplateAdaptorHttpClient(restTemplate);
httpClient.fetch(url);
verify(restTemplate).getForObject(eq(url), eq(String.class));
verify(restTemplate).getForEntity(eq(url), eq(Resource.class));
}

}
}

0 comments on commit 50fd34b

Please sign in to comment.