SEBSERV-467 fix plus added authentication to LMSSetup test

This commit is contained in:
anhefti 2023-10-02 12:03:39 +02:00
parent d6782075bc
commit 1d2c88c971
5 changed files with 28 additions and 3 deletions

View file

@ -163,6 +163,23 @@ public class OlatLmsAPITemplate extends AbstractCachedCourseAccess implements Lm
"lmsSetup:lmsClientsecret:notNull"));
}
final Result<OlatLmsRestTemplate> restTemplateResult = getRestTemplate();
if (restTemplateResult.hasError()) {
missingAttrs.add(APIMessage.fieldValidationError(
LMS_SETUP.ATTR_LMS_URL,
"lmsSetup:lmsUrl:url.noservice"));
} else {
final OlatLmsRestTemplate olatLmsRestTemplate = restTemplateResult.get();
try {
olatLmsRestTemplate.testAuthentication();
} catch (final Exception e) {
log.error("Failed to test Authentication: {}", e.getMessage());
missingAttrs.add(APIMessage.fieldValidationError(
LMS_SETUP.ATTR_LMS_URL,
"lmsSetup:lmsUrl:url.noaccess"));
}
}
if (!missingAttrs.isEmpty()) {
return LmsSetupTestResult.ofMissingAttributes(LmsType.OPEN_OLAT, missingAttrs);
}

View file

@ -32,6 +32,10 @@ public class OlatLmsRestTemplate extends RestTemplate {
private String token;
private ClientCredentialsResourceDetails details;
public void testAuthentication() {
authenticate();
}
public OlatLmsRestTemplate(final ClientCredentialsResourceDetails details) {
super();
this.details = details;
@ -45,7 +49,6 @@ public class OlatLmsRestTemplate extends RestTemplate {
final ClientHttpRequestExecution execution) throws IOException {
try {
// if there's no token, authenticate first
if (OlatLmsRestTemplate.this.token == null) {
authenticate();
@ -59,6 +62,7 @@ public class OlatLmsRestTemplate extends RestTemplate {
return execution.execute(request, body);
}
// otherwise, add the X-OLAT-TOKEN
request.getHeaders().set("accept", "application/json");
request.getHeaders().set("X-OLAT-TOKEN", OlatLmsRestTemplate.this.token);
@ -85,6 +89,7 @@ public class OlatLmsRestTemplate extends RestTemplate {
log.debug("OLAT [retry API call]: URL {}", request.getURI());
}
response.close();
response = execution.execute(request, body);
if (log.isDebugEnabled()) {
@ -97,7 +102,7 @@ public class OlatLmsRestTemplate extends RestTemplate {
} catch (final Exception e) {
// TODO find a way to better deal with Olat temporary unavailability
log.error("Unexpected error: ", e);
log.error("Unexpected error: {}", e.getMessage());
throw e;
}
}

View file

@ -25,7 +25,7 @@ sebserver.webservice.clean-db-on-startup=false
# webservice configuration
sebserver.init.adminaccount.gen-on-init=false
sebserver.webservice.distributed=true
sebserver.webservice.distributed=false
#sebserver.webservice.master.delay.threshold=10000
sebserver.webservice.http.external.scheme=http
sebserver.webservice.http.external.servername=localhost

View file

@ -111,6 +111,7 @@ sebserver.form.validation.fieldError.serverNotAvailable=No service seems to be a
sebserver.form.validation.fieldError.url.invalid=Invalid URL. The given URL cannot be reached.
sebserver.form.validation.fieldError.typeInvalid=This type is not implemented yet and cannot be used.
sebserver.form.validation.fieldError.url.noservice=The expected service is not available within the given URL and API access.
sebserver.form.validation.fieldError.url.noaccess=There has no access been granted by the service. Please check the given access credentials.
sebserver.form.validation.fieldError.thresholdDuplicate=There are duplicate threshold values.
sebserver.form.validation.fieldError.thresholdEmpty=There are missing values or colors for the threshold declaration
sebserver.form.validation.fieldError.invalidIP=Invalid IP v4. Please enter a valid IP-address (v4)

View file

@ -41,6 +41,8 @@ public class OlatLmsAPITemplateTest extends AdministrationAPIIntegrationTester {
private ExamConfigurationValueService examConfigurationValueService;
@Autowired
private CacheManager cacheManager;
@Autowired
private OlatLmsRestTemplate olatLmsRestTemplate;
@Test
public void testSetRestriction() throws Exception {