微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ALM 12 REST API 无法登录 ALM“身份验证失败 - 401”

如何解决ALM 12 REST API 无法登录 ALM“身份验证失败 - 401”

我使用的是 HP ALM 版本 12.53.193。我正在尝试通过 REST-API 自动上传测试结果。 我可以通过邮递员使用:

GET: https://[ourserver]/qcbin/authentication-point/authenticate
POST: https://[ourserver]/qcbin/rest/site-session

我知道我需要 cookie: LWSSO_COOKIE_KEY QCSession,ALM_USER,XSRF-令牌

但是,当我通过打字稿执行此操作时,我收到身份验证错误 401。这是我的代码片段。

  before('Before',async function () {
        config.auth = {
            username: "TestUser",password: "aabbccdd",}
        //Works
        url4 = "https://[ourserver]/qcbin/api/authentication/sign-in";
        let auth4 = await axios.get(url4,config)
        cookie1 = auth4.headers['set-cookie'][1].split(';')[0]
        console.log("cookie1: " + cookie1)
        console.log("authentication status: " + auth4.status)

        url1 = "https://[ourserver]/qcbin/authentication-point/authenticate";
        let auth = await axios.get(url1,config)
        cookie2 = auth.headers['set-cookie'][0].split(';')[0]
        console.log("cookie2: " + cookie2)
        console.log("authentication status: " + auth.status)

        let lwcookie = cookie2.toString().replace("LWSSO_COOKIE_KEY=","");
        console.log(lwcookie);

        let axiosConfig = {
            headers: {
                "Content-Type": "application/xml","Accept": "application/xml","cookie": lwcookie,}
        };

       url3 = "https://[ourserver]/qcbin/rest/site-session";
       let auth1 = await axios.post(url3,config,axiosConfig)
                .then(response =>{
                    console.log(response);
                })
                .catch(error => {
                    console.log(error.response);
                });
       /*cookie3 = auth1.headers['set-cookie'][0].split(';')[0]
            .then((response) => {
                console.log(response);
                },(error) => {
                console.log(error);
                }
            )*/
       /*cookie3 = auth1.headers['set-cookie'][0].split(';')[0]
         console.log("cookie: " + cookie3)
         console.log("authentication status: " + auth1.status)*/

    });

    it('Get Test ID',async function () {
        try {
        [Code to get Test ID but cannot authenticate to perform this]

        } catch (err) {
            throw new Error("'Get Test ID' was not successful.");
        }
    });

    after('After',async function () {
        utilsCommon.logInfo("Running the 'After' step.");
        try {
        } catch (err) {
            utilsCommon.logError("'After' step was unsuccessful.");
        }
    })

我的日志:

cookie1: QCSession=NzkyODgwMjc7R01PWEVQeis1SkpWbTZFajJkRG14USoqO1JFU1QgY2xpZW50OyA7IA..
authentication status: 200
cookie2: LWSSO_COOKIE_KEY=tCxH2kIzj6isTpQxPIxAmy3zAT8RFPDg3HRgsIZpr-ZuNh9bOm05MOZw-3nsaKcDOaaSdsb5FaywXaRS3CIcGMQd2AtQXURQwsa9DEJizv_KIZZCKx4ILQlB1rOPMZUfqBJp7ybBKWAW1rEmh02ic2Vu0CiuC1bGLTdFasUfjSciQoLIuslybA-3uwF2wtaeRYAYOwa0tUEzvKiE8ulCiOWYrv3VFSrqAg8XKUDJC2Mle8U7uyul7UnAgA9sDT27udGm22z2R0HejanwWvYUL55blXp4cbtYTjIFaAdau6AJkIpmj9yCArxp4FoKVHHb
authentication status: 200
tCxH2kIzj6isTpQxPIxAmy3zAT8RFPDg3HRgsIZpr-ZuNh9bOm05MOZw-3nsaKcDOaaSdsb5FaywXaRS3CIcGMQd2AtQXURQwsa9DEJizv_KIZZCKx4ILQlB1rOPMZUfqBJp7ybBKWAW1rEmh02ic2Vu0CiuC1bGLTdFasUfjSciQoLIuslybA-3uwF2wtaeRYAYOwa0tUEzvKiE8ulCiOWYrv3VFSrqAg8XKUDJC2Mle8U7uyul7UnAgA9sDT27udGm22z2R0HejanwWvYUL55blXp4cbtYTjIFaAdau6AJkIpmj9yCArxp4FoKVHHb
   {
  status: 401,statusText: "Authentication Failed. browser based integrations - to login append '?login-form-required=y' to the url you tried to access.",headers: {
    date: 'Wed,24 Feb 2021 11:09:14 GMT','x-content-type-options': 'nosniff','set-cookie': [
      'JSESSIONID=1sjx29b8l5p7s4ps0elbwip1h;Path=/qcbin;HttpOnly','BIGipServerfusionalm_8080=820110346.36895.0000; path=/; Httponly; Secure'
    ],'www-authenticate': 'LWSSO realm="http://[ourserver]:80/qcbin/authentication-point"','content-type': 'text/html; charset=ISO-8859-1','cache-control': 'must-revalidate,no-cache,no-store','content-length': '537',connection: 'close',server: 'Jetty(9.1.4.v20140401)'
  },config: {
    url: 'https://[ourserver]/qcbin/rest/site-session',method: 'post',data: '{"auth":{"username":"TestUser","password":"aabbccdd"}}',headers: {
      Accept: 'application/xml','Content-Type': 'application/xml',cookie: 'tCxH2kIzj6isTpQxPIxAmy3zAT8RFPDg3HRgsIZpr-ZuNh9bOm05MOZw-3nsaKcDOaaSdsb5FaywXaRS3CIcGMQd2AtQXURQwsa9DEJizv_KIZZCKx4ILQlB1rOPMZUfqBJp7ybBKWAW1rEmh02ic2Vu0CiuC1bGLTdFasUfjSciQoLIuslybA-3uwF2wtaeRYAYOwa0tUEzvKiE8ulCiOWYrv3VFSrqAg8XKUDJC2Mle8U7uyul7UnAgA9sDT27udGm22z2R0HejanwWvYUL55blXp4cbtYTjIFaAdau6AJkIpmj9yCArxp4FoKVHHb','User-Agent': 'axios/0.19.0','Content-Length': 58
    },transformRequest: [ [Function: transformRequest] ],transformResponse: [ [Function: transformResponse] ],timeout: 0,adapter: [Function: httpAdapter],xsrfCookieName: 'XSRF-TOKEN',xsrfheaderName: 'X-XSRF-TOKEN',maxContentLength: -1,validateStatus: [Function: validateStatus]
  },request: <ref *1> ClientRequest {
    _events: [Object: null prototype] {
      socket: [Function (anonymous)],abort: [Function (anonymous)],aborted: [Function (anonymous)],error: [Function (anonymous)],timeout: [Function (anonymous)],prefinish: [Function: requestOnPrefinish]
    },_eventsCount: 6,_maxListeners: undefined,outputData: [],outputSize: 0,writable: true,destroyed: false,_last: true,chunkedEncoding: false,shouldKeepAlive: false,_defaultKeepAlive: true,useChunkedEncodingByDefault: true,sendDate: false,_removedConnection: false,_removedContLen: false,_removedTE: false,_contentLength: null,_hasBody: true,_trailer: '',finished: true,_headerSent: true,socket: TLSSocket {
      _tlsOptions: [Object],_secureEstablished: true,_securePending: false,_newSessionPending: false,_controlReleased: true,secureConnecting: false,_SNICallback: null,servername: '[ourserver]',alpnProtocol: false,authorized: true,authorizationError: null,encrypted: true,_events: [Object: null prototype],_eventsCount: 10,connecting: false,_hadError: false,_parent: null,_host: '[ourserver]',_readableState: [ReadableState],_writableState: [WritableState],allowHalfOpen: false,_sockname: null,_pendingData: null,_pendingEncoding: '',server: undefined,_server: null,ssl: [TLSWrap],_requestCert: true,_rejectUnauthorized: true,parser: null,_httpMessage: [Circular *1],[Symbol(res)]: [TLSWrap],[Symbol(verified)]: true,[Symbol(pendingSession)]: null,[Symbol(async_id_symbol)]: 46,[Symbol(kHandle)]: [TLSWrap],[Symbol(kSetNoDelay)]: false,[Symbol(lastWriteQueueSize)]: 0,[Symbol(timeout)]: null,[Symbol(kBuffer)]: null,[Symbol(kBufferCb)]: null,[Symbol(kBufferGen)]: null,[Symbol(kCapture)]: false,[Symbol(kBytesRead)]: 0,[Symbol(kBytesWritten)]: 0,[Symbol(connect-options)]: [Object],[Symbol(RequestTimeout)]: undefined
    },_header: 'POST /qcbin/rest/site-session HTTP/1.1\r\n' +
      'Accept: application/xml\r\n' +
      'Content-Type: application/xml\r\n' +
      'cookie: tCxH2kIzj6isTpQxPIxAmy3zAT8RFPDg3HRgsIZpr-ZuNh9bOm05MOZw-3nsaKcDOaaSdsb5FaywXaRS3CIcGMQd2AtQXURQwsa9DEJizv_KIZZCKx4ILQlB1rOPMZUfqBJp7ybBKWAW1rEmh02ic2Vu0CiuC1bGLTdFasUfjSciQoLIuslybA-3uwF2wtaeRYAYOwa0tUEzvKiE8ulCiOWYrv3VFSrqAg8XKUDJC2Mle8U7uyul7UnAgA9sDT27udGm22z2R0HejanwWvYUL55blXp4cbtYTjIFaAdau6AJkIpmj9yCArxp4FoKVHHb\r\n' +
      'User-Agent: axios/0.19.0\r\n' +
      'Content-Length: 58\r\n' +
      'Host: [ourserver]\r\n' +
      'Connection: close\r\n' +
      '\r\n',_keepAliveTimeout: 0,_onPendingData: [Function: noopPendingOutput],agent: Agent {
      _events: [Object: null prototype],_eventsCount: 2,defaultPort: 443,protocol: 'https:',options: [Object],requests: {},sockets: [Object],freeSockets: {},keepAliveMsecs: 1000,keepAlive: false,maxSockets: Infinity,maxFreeSockets: 256,scheduling: 'fifo',maxTotalSockets: Infinity,totalSocketCount: 1,maxCachedSessions: 100,_sessionCache: [Object],[Symbol(kCapture)]: false
    },socketPath: undefined,method: 'POST',maxHeaderSize: undefined,insecureHTTPParser: undefined,path: '/qcbin/rest/site-session',_ended: true,res: IncomingMessage {
      _readableState: [ReadableState],_eventsCount: 3,socket: [TLSSocket],httpVersionMajor: 1,httpVersionMinor: 1,httpVersion: '1.1',complete: true,headers: [Object],rawHeaders: [Array],trailers: {},rawTrailers: [],aborted: false,upgrade: false,url: '',method: null,statusCode: 401,statusMessage: "Authentication Failed. browser based integrations - to login append '?login-form-required=y' to the url you tried to access.",client: [TLSSocket],_consuming: false,_dumped: false,req: [Circular *1],responseUrl: 'https://[ourserver]/qcbin/rest/site-session',redirects: [],timeoutCb: null,upgradeOrConnect: false,maxHeadersCount: null,reusedSocket: false,host: '[ourserver]',_redirectable: Writable {
      _writableState: [WritableState],_options: [Object],_redirectCount: 0,_redirects: [],_requestBodyLength: 58,_requestBodyBuffers: [],_onNativeResponse: [Function (anonymous)],_currentRequest: [Circular *1],_currentUrl: 'https://[ourserver]/qcbin/rest/site-session',[Symbol(kNeedDrain)]: false,[Symbol(corked)]: 0,[Symbol(kOutHeaders)]: [Object: null prototype] {
      accept: [Array],'content-type': [Array],cookie: [Array],'user-agent': [Array],'content-length': [Array],host: [Array]
    }
  },data: '<html>\n' +
    '<head>\n' +
    '<Meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>\n' +
    "<title>Error 401 Authentication Failed. browser based integrations - to login append '?login-form-required=y' to the url you tried to access.</title>\n" +
    '</head>\n' +
    '<body><h2>HTTP ERROR 401</h2>\n' +
    '<p>Problem accessing /qcbin/rest/site-session. Reason:\n' +
    "<pre>    Authentication Failed. browser based integrations - to login append '?login-form-required=y' to the url you tried to access.</pre></p><hr><i><small>Powered by Jetty://</small></i><hr/>\n" +
    '\n' +
    '</body>\n' +
    '</html>\n'
}

我很困惑,因为我收到了: LWSSO_COOKIE_KEY 并且基于这个 cookie,我应该能够获得其余的 cookie,以便能够从 ALM 进行身份验证和更新/获取测试,对吗?

有人可以帮我吗?我做错了什么 非常感谢!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。