Java Code Examples for io.restassured.RestAssured#authentication()

The following examples show how to use io.restassured.RestAssured#authentication() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AppTestBase.java    From microprofile-open-api with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void configureRestAssured() throws MalformedURLException {
    // set base URI and port number to use for all requests
    serverUrl = System.getProperty("test.url");
    String protocol = DEFAULT_PROTOCOL;
    String host = DEFAULT_HOST;
    int port = DEFAULT_PORT;

    if (serverUrl != null) {
        URL url = new URL(serverUrl);
        protocol = url.getProtocol();
        host = url.getHost();
        port = (url.getPort() == -1) ? DEFAULT_PORT : url.getPort();
    }

    RestAssured.baseURI = protocol + "://" + host;
    RestAssured.port = port;

    username = System.getProperty("test.user");
    password = System.getProperty("test.pwd");

    if (username != null && password != null) {
        RestAssured.authentication = RestAssured.basic(username, password);
        RestAssured.useRelaxedHTTPSValidation();
    }
    RestAssured.defaultParser = Parser.JSON;

    if (StringUtils.isBlank(serverUrl)) {
        serverUrl = DEFAULT_PROTOCOL + "://" + DEFAULT_HOST + ":" + DEFAULT_PORT;
    }
}
 
Example 2
Source File: MpMetricOptionalTest.java    From microprofile-metrics with Apache License 2.0 5 votes vote down vote up
@BeforeClass
static public void setup() throws MalformedURLException {
    // set base URI and port number to use for all requests
    String serverUrl = System.getProperty("test.url");
    String protocol = DEFAULT_PROTOCOL;
    String host = DEFAULT_HOST;
    int port = DEFAULT_PORT;

    if (serverUrl != null) {
        URL url = new URL(serverUrl);
        protocol = url.getProtocol();
        host = url.getHost();
        port = (url.getPort() == -1) ? DEFAULT_PORT : url.getPort();
    }

    RestAssured.baseURI = protocol + "://" + host;
    RestAssured.port = port;

    // set user name and password to use for basic authentication for all requests
    String userName = System.getProperty("test.user");
    String password = System.getProperty("test.pwd");

    if (userName != null && password != null) {
        RestAssured.authentication = RestAssured.basic(userName, password);
        RestAssured.useRelaxedHTTPSValidation();
    }

    contextRoot = System.getProperty("context.root", "/optionalTCK");

    applicationPort = Integer.parseInt(System.getProperty("application.port", Integer.toString(port)));

}
 
Example 3
Source File: ReusedMetricsTest.java    From microprofile-metrics with Apache License 2.0 5 votes vote down vote up
@BeforeClass
static public void setup() throws MalformedURLException {
    // set base URI and port number to use for all requests
    String serverUrl = System.getProperty("test.url");
    String protocol = DEFAULT_PROTOCOL;
    String host = DEFAULT_HOST;
    int port = DEFAULT_PORT;

    if (serverUrl != null) {
        URL url = new URL(serverUrl);
        protocol = url.getProtocol();
        host = url.getHost();
        port = (url.getPort() == -1) ? DEFAULT_PORT : url.getPort();
    }

    RestAssured.baseURI = protocol + "://" + host;
    RestAssured.port = port;

    // set user name and password to use for basic authentication for all requests
    String userName = System.getProperty("test.user");
    String password = System.getProperty("test.pwd");

    if (userName != null && password != null) {
        RestAssured.authentication = RestAssured.basic(userName, password);
        RestAssured.useRelaxedHTTPSValidation();
    }

}
 
Example 4
Source File: MpMetricTest.java    From microprofile-metrics with Apache License 2.0 5 votes vote down vote up
@BeforeClass
static public void setup() throws MalformedURLException {
    // set base URI and port number to use for all requests
    String serverUrl = System.getProperty("test.url");
    String protocol = DEFAULT_PROTOCOL;
    String host = DEFAULT_HOST;
    int port = DEFAULT_PORT;

    if (serverUrl != null) {
        URL url = new URL(serverUrl);
        protocol = url.getProtocol();
        host = url.getHost();
        port = (url.getPort() == -1) ? DEFAULT_PORT : url.getPort();
    }

    RestAssured.baseURI = protocol + "://" + host;
    RestAssured.port = port;

    // set user name and password to use for basic authentication for all requests
    String userName = System.getProperty("test.user");
    String password = System.getProperty("test.pwd");

    if (userName != null && password != null) {
        RestAssured.authentication = RestAssured.basic(userName, password);
        RestAssured.useRelaxedHTTPSValidation();
    }

}
 
Example 5
Source File: RestBase.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
	RestAssured.baseURI = this.url;
	if (StringUtils.hasText(this.username)) {
		RestAssured.authentication = RestAssured.basic(this.username, this.password);
	}
}
 
Example 6
Source File: LoginActions.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Removes authentication header
 */
public void removeAuthenticationHeader()
{
    RestAssured.authentication = RestAssured.DEFAULT_AUTH;
}
 
Example 7
Source File: LoginActions.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Logs in with oAuth2 token
 * @param token
 */
public void loginWithToken( String token )
{
    RestAssured.authentication = oauth2( token );
}
 
Example 8
Source File: RestApiLiveTest.java    From tutorials with MIT License 4 votes vote down vote up
@Before
public void setUp() {
    RestAssured.authentication = preemptive().basic("user", "userPass");
}
 
Example 9
Source File: RestApiLiveTest.java    From tutorials with MIT License 4 votes vote down vote up
@Before
public void setUp() {
    RestAssured.authentication = preemptive().basic("user", "userPass");
}
 
Example 10
Source File: LoginActions.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Adds authentication header that is used in all consecutive requests
 *
 * @param username
 * @param password
 */
public void addAuthenticationHeader( final String username, final String password )
{
    RestAssured.authentication = RestAssured.preemptive().basic( username, password );
}