11-03-2022 08:04 AM - edited 11-03-2022 08:08 AM
Dear all,
I've been working a lot, lately, on the vmanage API and building a tool around it for monitoring purposes. Currently I'm implementing a lot of unittesting to improve the quality of my code. I thought that I had covered all cases with the login and logoff actions, but I couldn't be more wrong!
The vManage will always provide a 200 status_code as long as it gets HTML back. However, the actual error code (locked account?) is then inside the HTML. Besides the fact that this is just plain dumb, here's my real problem: I really suck at regex and have trouble getting the error from the webpage.
As an example, when trying to fetch a cookie, I have the following regex to capture particular errors that might be visible in the HTML (requests.status_code eq 200!!!):
(?<=class=\\\'errorMessageBox \\\'>)(.*?)(?=</p>)
'<html>\n
<head>\n
<meta charset="utf-8">\n <title>Cisco vManage</title>\n
<link rel="stylesheet" type="text/css" href="/styles/login.css">\n
<link rel="stylesheet" type="text/css" href="/fonts/font-awesome-4.2.0/css/font-awesome.min.css">\n
<link rel="icon" type="image/ico" href="/images/favicon.ico" />\n
</head>\n
<body onload="init()">\n<div name="Login" class="loginContainer">\n <div class="loginInnerContainer">\n
<!-- <div class="productCategory">Cisco SD-WAN</div> -->\n <form class="loginFormStyle" name="loginForm"
id="loginForm" action="j_security_check" autocomplete="off">\n <div name="logoMainContainer"
class="logoMainContainer"></div>\n
<!-- <div class="brand-logo-text"><span>Cisco vManage</span></div> -->\n <img
src="/images/cisco_vmanage_logo.svg" alt="Cisco vManage" class="center">\n <div
id="login-check-consent">\n
<!-- show the notice message here -->\n
</div>\n <div id="error-info-container">\n <div id="error-info">\n <div id="errorInfoIcon"
name="errorInfoIcon" class="errorInfoIcon">\n <img src="/images/error.svg"
alt="Login Error">\n </div>\n <div id="errorInfoText">\n <span id="errorMessageBox"
name="errorMessageBox" class="errorMessageBox"></span>\n <span id="errorDetails">\n <ul>
\n <li>If username and password are valid, user account is locked. Wait for some
time and try again or contact Administrator</li>\n <li>If username and password
are valid, password has expired. Contact Administrator</li>\n </ul>\n </span>\n
</div>\n </div>\n </div>\n <div id="reboot_message" class="reboot-message-block">\n <div
class="reboot-message" id="rebootStatusMessage"></div>\n
<!-- <i class="fa fa-circle-o-notch fa-spin fa-3x fa-fw" style="color: #0bbbe9;"></i> -->\n <img
src="/images/loader.png" alt="Loader" class="spinner">\n
</div>\n <div id="login_message" style="display: none;">\n <div class=\'onyx-groupbox login-wrap\'
id="login-wrap" name="inputFields">\n <div id="frm_username">\n <div
class="onyx-input-decorator login-input">\n <input type="text" class="login-input-value"
size="20" autocomplete="off" \n id="j_username" name="j_username" maxlength="64"
placeholder="Username" value="" oninput="setView(\'1\')" autofocus />\n <label
for="j_username">Username</label>\n </div>\n </div>\n <div id="tacuser_container">\n
<div id="frm_challenge">\n <div class="onyx-input-decorator login-input">\n <input
type="text" class="login-input-value" size="34" autocomplete="off" \n
id="j_challenge" name="j_challenge" placeholder="Challenge Key" value=""
onkeyup="validateTacForm()" />\n <label for="j_challenge">Challenge
Key</label>\n <div class="tacuser-icon-container">\n <input type="checkbox"
id="copy_challenge" onchange="copyToClipboard()" />\n <label
for="copy_challenge" class="icon"></label>\n <input type="checkbox"
id="refresh_challenge" onchange="getChallenge(\'rekey\')" />\n <label
for="refresh_challenge" class="icon"></label>\n </div>\n </div>\n </div>\n
<div id="frm_token">\n \n <div class="onyx-input-decorator login-input">\n <input
type="text" class="login-input-value" size="40" autocomplete="off" \n
id="j_token" name="j_token" placeholder="Access Token" value=""
onpaste="validateTacForm()" onkeyup="validateTacForm()" />\n <label
for="j_token">Access Token</label>\n </div>\n </div>\n </div>\n <div
id="frm_password">\n \n <div class="onyx-input-decorator login-input input-password">\n
<input type="password" class="login-input-value" size="20" autocomplete="new-password"
\n id="j_password" name="j_password" placeholder="Password" value=""
oninput="setView(\'2\')" />\n <label for="j_password">Password</label>\n <div
class="toggle-password-container">\n <input type="checkbox" id="toggle_visibility"
onchange="toggleVisibility()" />\n <label for="toggle_visibility"
class="icon"></label>\n </div>\n </div>\n </div>\n </div>\n <div
id="login-check-wrap">\n <div class="login-check-row">\n <div class="login-check-left">\n <input
type="checkbox" id="j_fedrampuser" name="j_fedrampuser" onclick="toggleLogin()">\n
</div>\n <div class="login-check-right" id="login-check-wrap-confirm">\n
<!-- show the confirm message here -->\n
</div>\n </div>\n </div>\n <div class=\'onyx-sample-tools login-wrap\'>\n <input
type="button" onclick="nextStep()" name="continue" value="Continue"
class="login-button-disabled" id="continueBtn" />\n <input type="button"
onclick="return validateForm()" name="submit" value="Log In" class="login-button-disabled"
id="loginBtn" />\n </div>\n </div>\n <input type="hidden" id="formType" name="formType" />\n
</form>\n
</div>\n</div>\n
<script type="text/javascript" src="/javascript/jquery-3.5.1.min.js"></script>\n
<script type="text/javascript" src="/javascript/login.js"></script>\n
</body>\n
</html>\n'
(?<=span id=\"errorDetails\">)(.|\n)*?(?=</span>)
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide