Skip to content

Commit

Permalink
Refactor security test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ldclakmal committed Jun 9, 2021
1 parent 11bec99 commit eb74e30
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 61 deletions.
6 changes: 3 additions & 3 deletions http-ballerina-tests/tests/auth_client_auth_handler_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ isolated function testClientSelfSignedJwtAuthHandler() {
@test:Config {}
isolated function testClientOAuth2Handler() {
http:OAuth2ClientCredentialsGrantConfig config1 = {
tokenUrl: "https://localhost:" + oauth2StsPort.toString() + "/oauth2/token",
tokenUrl: "https://localhost:" + stsPort.toString() + "/oauth2/token",
clientId: "3MVG9YDQS5WtC11paU2WcQjBB3L5w4gz52uriT8ksZ3nUVjKvrfQMrU4uvZohTftxStwNEW4cfStBEGRxRL68",
clientSecret: "9205371918321623741",
scopes: ["token-scope1", "token-scope2"],
Expand All @@ -149,7 +149,7 @@ isolated function testClientOAuth2Handler() {
};

http:OAuth2PasswordGrantConfig config2 = {
tokenUrl: "https://localhost:" + oauth2StsPort.toString() + "/oauth2/token",
tokenUrl: "https://localhost:" + stsPort.toString() + "/oauth2/token",
username: "johndoe",
password: "A3ddj3w",
clientId: "3MVG9YDQS5WtC11paU2WcQjBB3L5w4gz52uriT8ksZ3nUVjKvrfQMrU4uvZohTftxStwNEW4cfStBEGRxRL68",
Expand All @@ -166,7 +166,7 @@ isolated function testClientOAuth2Handler() {
};

http:OAuth2RefreshTokenGrantConfig config3 = {
refreshUrl: "https://localhost:" + oauth2StsPort.toString() + "/oauth2/token",
refreshUrl: "https://localhost:" + stsPort.toString() + "/oauth2/token",
refreshToken: "XlfBs91yquexJqDaKEMzVg==",
clientId: "3MVG9YDQS5WtC11paU2WcQjBB3L5w4gz52uriT8ksZ3nUVjKvrfQMrU4uvZohTftxStwNEW4cfStBEGRxRL68",
clientSecret: "9205371918321623741",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ isolated function testListenerJwtAuthHandlerAuthnFailure() {
@test:Config {}
function testListenerOAuth2HandlerAuthSuccess() {
http:OAuth2IntrospectionConfig config = {
url: "https://localhost:" + oauth2StsPort.toString() + "/oauth2/introspect",
url: "https://localhost:" + stsPort.toString() + "/oauth2/introspect",
tokenTypeHint: "access_token",
scopeKey: "scp",
clientConfig: {
Expand Down Expand Up @@ -311,7 +311,7 @@ function testListenerOAuth2HandlerAuthSuccess() {
@test:Config {}
function testListenerOAuth2HandlerAuthzFailure() {
http:OAuth2IntrospectionConfig config = {
url: "https://localhost:" + oauth2StsPort.toString() + "/oauth2/introspect",
url: "https://localhost:" + stsPort.toString() + "/oauth2/introspect",
tokenTypeHint: "access_token",
scopeKey: "scp",
clientConfig: {
Expand All @@ -336,7 +336,7 @@ function testListenerOAuth2HandlerAuthzFailure() {
@test:Config {}
function testListenerOAuth2HandlerAuthnFailure() {
http:OAuth2IntrospectionConfig config = {
url: "https://localhost:" + oauth2StsPort.toString() + "/oauth2/introspect",
url: "https://localhost:" + stsPort.toString() + "/oauth2/introspect",
tokenTypeHint: "access_token",
scopeKey: "scp",
clientConfig: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
import ballerina/http;
import ballerina/test;

listener http:Listener authListener = new(securedListenerPort,
secureSocket = {
listener http:Listener authListener = new(securedListenerPort, {
secureSocket: {
key: {
path: KEYSTORE_PATH,
password: "ballerina"
}
}
);
});

// Unsecured service - Unsecured resource with different combination of resource signature parameters

Expand Down Expand Up @@ -156,7 +156,7 @@ function testJwtAuthServiceAuthnFailure() {
auth: [
{
oauth2IntrospectionConfig: {
url: "https://localhost:" + oauth2StsPort.toString() + "/oauth2/introspect",
url: "https://localhost:" + stsPort.toString() + "/oauth2/introspect",
tokenTypeHint: "access_token",
scopeKey: "scp",
clientConfig: {
Expand Down Expand Up @@ -240,7 +240,7 @@ service /foo on authListener {
auth: [
{
oauth2IntrospectionConfig: {
url: "https://localhost:" + oauth2StsPort.toString() + "/oauth2/introspect",
url: "https://localhost:" + stsPort.toString() + "/oauth2/introspect",
tokenTypeHint: "access_token",
scopeKey: "scp",
clientConfig: {
Expand Down Expand Up @@ -318,7 +318,7 @@ function testOAuth2ResourceAuthnFailure() {
auth: [
{
oauth2IntrospectionConfig: {
url: "https://localhost:" + oauth2StsPort.toString() + "/oauth2/introspect",
url: "https://localhost:" + stsPort.toString() + "/oauth2/introspect",
tokenTypeHint: "access_token",
scopeKey: "scp",
clientConfig: {
Expand Down Expand Up @@ -386,7 +386,7 @@ function testServiceResourceAuthnFailure() {
auth: [
{
oauth2IntrospectionConfig: {
url: "https://localhost:" + oauth2StsPort.toString() + "/oauth2/introspect",
url: "https://localhost:" + stsPort.toString() + "/oauth2/introspect",
tokenTypeHint: "access_token",
scopeKey: "scp",
clientConfig: {
Expand Down Expand Up @@ -455,7 +455,7 @@ service /bar on authListener {
auth: [
{
oauth2IntrospectionConfig: {
url: "https://localhost:" + oauth2StsPort.toString() + "/oauth2/introspect",
url: "https://localhost:" + stsPort.toString() + "/oauth2/introspect",
tokenTypeHint: "access_token",
scopeKey: "scp",
clientConfig: {
Expand Down
4 changes: 2 additions & 2 deletions http-ballerina-tests/tests/auth_test_commons.bal
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ isolated function sendJwtRequest(string path) returns http:Response|http:ClientE
isolated function sendOAuth2TokenRequest(string path) returns http:Response|http:ClientError {
http:Client clientEP = checkpanic new("https://localhost:" + securedListenerPort.toString(), {
auth: {
tokenUrl: "https://localhost:" + oauth2StsPort.toString() + "/oauth2/token",
tokenUrl: "https://localhost:" + stsPort.toString() + "/oauth2/token",
clientId: "3MVG9YDQS5WtC11paU2WcQjBB3L5w4gz52uriT8ksZ3nUVjKvrfQMrU4uvZohTftxStwNEW4cfStBEGRxRL68",
clientSecret: "9205371918321623741",
clientConfig: {
Expand Down Expand Up @@ -222,7 +222,7 @@ isolated function assertUnauthorized(http:Response|http:ClientError response) {
}

// The mock authorization server, based with https://hub.docker.com/repository/docker/ldclakmal/ballerina-sts
listener http:Listener sts = new(oauth2StsPort, {
listener http:Listener sts = new(stsPort, {
secureSocket: {
key: {
path: KEYSTORE_PATH,
Expand Down
2 changes: 1 addition & 1 deletion http-ballerina-tests/tests/http2_mutual_ssl_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ service /http2Service on http2Listener {
}

http:ClientConfiguration http2MutualSslClientConf = {
secureSocket:{
secureSocket: {
key:{
path: "tests/certsandkeys/ballerinaKeystore.p12",
password: "ballerina"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ service /mutualSslService on mutualSslistener {
}

http:ClientConfiguration certsClientConf = {
secureSocket:{
secureSocket: {
cert: "tests/certsandkeys/public.crt",
key: {
keyFile: "tests/certsandkeys/private.key",
Expand Down
80 changes: 40 additions & 40 deletions http-ballerina-tests/tests/listener_init_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ public function testEmptyKeyFile() {
@test:Config {}
public function testEmptyTrusStoreFile() {
http:Listener|http:Error testListener = new(9249, {
secureSocket: {
key: {
certFile: "tests/certsandkeys/public.crt",
keyFile: "tests/certsandkeys/private.key"
},
mutualSsl: {
verifyClient: http:REQUIRE,
cert: ""
}
}
});
secureSocket: {
key: {
certFile: "tests/certsandkeys/public.crt",
keyFile: "tests/certsandkeys/private.key"
},
mutualSsl: {
verifyClient: http:REQUIRE,
cert: ""
}
}
});
if (testListener is http:Listener) {
test:assertFail(msg = "Found unexpected output: Expected an empty cert file error" );
} else {
Expand All @@ -109,20 +109,20 @@ public function testEmptyTrusStoreFile() {
@test:Config {}
public function testEmptyTrusStorePassword() {
http:Listener|http:Error testListener = new(9249, {
secureSocket: {
key: {
certFile: "tests/certsandkeys/public.crt",
keyFile: "tests/certsandkeys/private.key"
},
mutualSsl: {
verifyClient: http:REQUIRE,
cert: {
path: "tests/certsandkeys/ballerinaTruststore.p12",
password: ""
}
}
}
});
secureSocket: {
key: {
certFile: "tests/certsandkeys/public.crt",
keyFile: "tests/certsandkeys/private.key"
},
mutualSsl: {
verifyClient: http:REQUIRE,
cert: {
path: "tests/certsandkeys/ballerinaTruststore.p12",
password: ""
}
}
}
});
if (testListener is http:Listener) {
test:assertFail(msg = "Found unexpected output: Expected an empty password error" );
} else {
Expand All @@ -133,21 +133,21 @@ public function testEmptyTrusStorePassword() {
@test:Config {}
public function testEmptyTrustStore() {
http:Listener|http:Error testListener = new(9249, {
host: "",
secureSocket: {
key: {
certFile: "tests/certsandkeys/public.crt",
keyFile: "tests/certsandkeys/private.key"
},
mutualSsl: {
verifyClient: http:REQUIRE,
cert: {
path: "",
password: "ballerina"
}
}
}
});
host: "",
secureSocket: {
key: {
certFile: "tests/certsandkeys/public.crt",
keyFile: "tests/certsandkeys/private.key"
},
mutualSsl: {
verifyClient: http:REQUIRE,
cert: {
path: "",
password: "ballerina"
}
}
}
});
if (testListener is http:Listener) {
test:assertFail(msg = "Found unexpected output: Expected an empty truststore error" );
} else {
Expand Down
2 changes: 1 addition & 1 deletion http-ballerina-tests/tests/ssl_mutual_ssl_with_certs.bal
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ service /mutualSSLService on mutualSSLListener {
}

http:ClientConfiguration mutualSslCertClientConf = {
secureSocket:{
secureSocket: {
cert: "tests/certsandkeys/public.crt",
key: {
keyFile: "tests/certsandkeys/private.key",
Expand Down
4 changes: 2 additions & 2 deletions http-ballerina-tests/tests/test_service_ports.bal
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,5 @@ const int http2RetryFunctionTestPort1 = 9606;
const int http2RetryFunctionTestPort2 = 9607;

//Security
const int oauth2StsPort = 9401;
const int securedListenerPort = 9402;
const int securedListenerPort = 9400;
const int stsPort = 9445;

0 comments on commit eb74e30

Please sign in to comment.