Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: specify content type when validating OIDC #3902

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
import io.jsonwebtoken.SignatureAlgorithm;
import org.apache.commons.codec.binary.Base64;
import org.hamcrest.core.Is;
import org.junit.jupiter.api.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
Expand All @@ -26,12 +29,17 @@
import org.zowe.apiml.util.config.ConfigReader;
import org.zowe.apiml.util.config.ConfigReaderZaasClient;
import org.zowe.apiml.zaasclient.config.ConfigProperties;
import org.zowe.apiml.zaasclient.exception.*;
import org.zowe.apiml.zaasclient.exception.ZaasClientErrorCodes;
import org.zowe.apiml.zaasclient.exception.ZaasClientException;
import org.zowe.apiml.zaasclient.exception.ZaasConfigurationException;
import org.zowe.apiml.zaasclient.service.ZaasClient;
import org.zowe.apiml.zaasclient.service.ZaasToken;
import org.zowe.apiml.zaasclient.service.internal.ZaasClientImpl;

import java.io.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.security.*;
import java.security.cert.CertificateException;
Expand Down Expand Up @@ -256,16 +264,19 @@ void givenEmptyToken() {
}

@Nested
@Tag("OktaOauth2Test")
class WhenOidcQuery {

private static final String VALID_TOKEN_NO_MAPPING = SecurityUtils.validOktaAccessToken(false);

@Test
void givenValidOidcToken_thenValidDetailsAreProvided() throws ZaasClientException {
var validationResult = tokenService.validateOidc(VALID_TOKEN_NO_MAPPING);
assertNotNull(validationResult);
assertTrue(validationResult.isValid());
}

@Test
void givenInvalidOidcToken_thenNotValidIsIssued() throws ZaasClientException {
var validationResult = tokenService.validateOidc("invalidtoken");
assertNotNull(validationResult);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ private ClassicHttpRequest validateOidcToken(String oidcToken) throws JsonProces
String json = objectMapper.writeValueAsString(new TokenRequest(oidcToken));
var entity = new StringEntity(json);
httpPost.setEntity(entity);
httpPost.setHeader("Content-Type", "application/json");
return httpPost;
}

Expand Down
Loading