//
// Test HTTP Basic with valid user name and password
//
void testBasicAuthSuccess()
{
    String authHeader;

    AuthenticationManager  authManager;

    AuthenticationInfo* authInfo = new AuthenticationInfo(true);

    String userPass = guestUser;
    userPass.append(":");
    userPass.append(guestPassword);

    authHeader.append(basicHeader);
    authHeader.append(encodeUserPass(userPass));

    Boolean authenticated;
    // test case looks for success, initialize with failure
    AuthenticationStatus authStatus(AUTHSC_UNAUTHORIZED);

    authStatus = authManager.performHttpAuthentication(authHeader, authInfo);
    authenticated = authStatus.isSuccess();

    if (verbose)
    {
        cout << "Authentication of user " + guestUser + " returned with: ";
        cout << authenticated << endl;
    }

    delete authInfo;

    //PEGASUS_TEST_ASSERT(authenticated);
}
//
// Test with valid user name and password 
// (Assuming there is a valid CIM user 'guest' with password 'guest')
//
void testAuthenticationSuccess()
{
    String authHeader = String::EMPTY;

    BasicAuthenticationHandler  basicAuthHandler;

    AuthenticationInfo* authInfo = new AuthenticationInfo(true);

    String userPass = guestUser;
    userPass.append(":");
    userPass.append(guestPassword);

    authHeader.append(encodeUserPass(userPass));

    Boolean authenticated;

    authenticated = basicAuthHandler.authenticate(authHeader, authInfo);

    if (authenticated)
        if (verbose) cout << "User " + guestUser + " authenticated successfully." << endl;
    else
        if (verbose) cout << "User " + guestUser + " authentication failed." << endl;

    delete authInfo;

    //PEGASUS_ASSERT(authenticated);
}
Exemple #3
0
/**
* \brief Check if user and password encoded in base64 is valid.
*
* \param userPass user and password encoded in base64 to check.
*
* \return uint8_t result is equals - 1, if error - 0.
*/
uint8_t baUserPassIsValid( char * userPass )
{
    char buf[MAX_BASE64_LEN + 1];
    encodeUserPass(buf);
    
    return strcmp(buf, userPass) == 0 ? 1 : 0;
}
//
// Test with invalid userPass (with no ':' separator)
//
void testAuthenticationFailure_1()
{
    String authHeader = String::EMPTY;
    Boolean authenticated;

    BasicAuthenticationHandler  basicAuthHandler;

    AuthenticationInfo* authInfo = new AuthenticationInfo(true);

    //
    // Test with invalid user password string
    //
    String userPass = testUser;
    userPass.append(guestPassword);

    authHeader.append(encodeUserPass(userPass));

    authenticated = basicAuthHandler.authenticate(authHeader, authInfo);

    if (authenticated)
        if (verbose) cout << "User " + testUser + " authenticated successfully." << endl;
    else
        if (verbose) cout << "User " + testUser + " authentication failed." << endl;

    delete authInfo;

    PEGASUS_ASSERT(!authenticated);
}