Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot publish results to xray jira #6

Open
srihmallampati opened this issue Oct 7, 2022 · 12 comments
Open

Cannot publish results to xray jira #6

srihmallampati opened this issue Oct 7, 2022 · 12 comments

Comments

@srihmallampati
Copy link

srihmallampati commented Oct 7, 2022

I have set my system environments (Bearer authentication) for Xray Cloud:

(Yes, i have set them on the pipeline environmental variables)
export XRAY_API_BASE_URL= "https://xray.cloud.getxray.app"
export XRAY_CLIENT_ID=
export XRAY_CLIENT_SECRET=

Using the command "- behave -f allure_behave.formatter:AllureFormatter -o report/allure/results -f pretty --f xray ./features/" I am running the test

And on the Feature file I have added the Test execution at the top followed by test case if for the scenario

Feature file:
@jira.test_execution('TEST-xxx')
Feature: feature name
Background: Common Steps
Given xxx
@jira.testcase('TEST-xxxx')
Scenario: Scenario name

On the pipeline I get below error -
HTTPError: Could not post to JIRA service https://xray.cloud.getxray.app/. Response status code: 404
Exception JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/requests/models.py", line 971, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/local/lib/python3.10/json/init.py", line 346, in loads
return _default_decoder.decode(s)
File "/usr/local/lib/python3.10/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/lib/python3.10/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/bin/behave", line 8, in
sys.exit(main())
File "/usr/local/lib/python3.10/site-packages/behave/main.py", line 183, in main
return run_behave(config)
File "/usr/local/lib/python3.10/site-packages/behave/main.py", line 127, in run_behave
failed = runner.run()
File "/usr/local/lib/python3.10/site-packages/behave/runner.py", line 804, in run
return self.run_with_paths()
File "/usr/local/lib/python3.10/site-packages/behave/runner.py", line 824, in run_with_paths
return self.run_model()
File "/usr/local/lib/python3.10/site-packages/behave/runner.py", line 626, in run_model
failed = feature.run(self)
File "/usr/local/lib/python3.10/site-packages/behave/model.py", line 350, in run
formatter.eof()
File "/usr/local/lib/python3.10/site-packages/behave_xray/formatter.py", line 127, in eof
self.xray_publisher.publish(self.test_execution.as_dict())
File "/usr/local/lib/python3.10/site-packages/behave_xray/xray_publisher.py", line 51, in publish
result = self.publish_xray_results(self.endpoint_url, self.auth, test_execution)
File "/usr/local/lib/python3.10/site-packages/behave_xray/xray_publisher.py", line 45, in publish_xray_results
_logger.error('Response error: %s', response.json())
File "/usr/local/lib/python3.10/site-packages/requests/models.py", line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

@fundakol
Copy link
Owner

fundakol commented Oct 9, 2022

Could you try install version 0.1.2? I fixed a bug with wrong endpoint for cloud sever.

@srihmallampati
Copy link
Author

Hi,
Updated to the latest version. Still not publishing to xray
below is the error -

requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://xray.cloud.getxray.app/api/v2/import/execution
Error message from server: Invalid JWT: JsonWebTokenError: invalid token
Could not publish results to Jira XRAY
HTTPError: Could not post to JIRA service at https://xray.cloud.getxray.app/api/v2/import/execution. Response status code: 401
Error message from server: Invalid JWT: JsonWebTokenError: invalid token

@fundakol
Copy link
Owner

There is only the bearer authentication implemented so far. It seems you need a token authentication.

@srihmallampati
Copy link
Author

srihmallampati commented Oct 10, 2022

We are implementing (Bearer authentication) as on the document

  • export XRAY_API_BASE_URL=https://xray.cloud.getxray.app
  • export XRAY_CLIENT_ID=${PRJ_XRAY_CLIENT_ID}
  • export XRAY_CLIENT_SECRET=${PRJ_XRAY_CLIENT_SECRET}

Is this the right way ? (we set up the client id and the secret on our environment variables with in the pipeline)*

HTTPError: Could not post to JIRA service at https://xray.cloud.getxray.app/api/v2/import/execution. Response status code: 401
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/behave_xray/xray_publisher.py", line 41, in publish_xray_results
response.raise_for_status()
File "/usr/local/lib/python3.10/site-packages/requests/models.py", line 1021, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://xray.cloud.getxray.app/api/v2/import/execution
Error message from server: Invalid JWT: JsonWebTokenError: invalid token
Could not publish results to Jira XRAY
HTTPError: Could not post to JIRA service at https://xray.cloud.getxray.app/api/v2/import/execution. Response status code: 401
Error message from server: Invalid JWT: JsonWebTokenError: invalid token

@fundakol
Copy link
Owner

If you are using token authentication for your Jira server you should generate it from Jira account configuration. And then you should use it instead of client id and secret.

Can you try install package from branch add_token_auth like so:
pip install git+https://github.com/fundakol/behave-xray@add_token_auth
and setup url and token:

$ export XRAY_API_BASE_URL=<jira URL>
$ export XRAY_TOKEN=<token created in Jira Xray>

And let me know if it helped.

@srihmallampati
Copy link
Author

srihmallampati commented Oct 17, 2022

I get this error now
HTTPError: Could not post to JIRA service at https://xray.cloud.getxray.app/rest/raven/2.0/import/execution. Response status code: 404
Traceback (most recent call last):
File "/usr/local/src/behave-xray/src/behave_xray/xray_publisher.py", line 41, in publish_xray_results
response.raise_for_status()
File "/usr/local/lib/python3.10/site-packages/requests/models.py", line 1021, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://xray.cloud.getxray.app/rest/raven/2.0/import/execution
Exception JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Traceback (most recent call last):
File "/usr/local/lib/python3.10/site-packages/requests/models.py", line 971, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/local/lib/python3.10/json/init.py", line 346, in loads
return _default_decoder.decode(s)
File "/usr/local/lib/python3.10/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/lib/python3.10/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/bin/behave", line 8, in
sys.exit(main())
File "/usr/local/lib/python3.10/site-packages/behave/main.py", line 183, in main
return run_behave(config)
File "/usr/local/lib/python3.10/site-packages/behave/main.py", line 127, in run_behave
failed = runner.run()
File "/usr/local/lib/python3.10/site-packages/behave/runner.py", line 804, in run
return self.run_with_paths()
File "/usr/local/lib/python3.10/site-packages/behave/runner.py", line 824, in run_with_paths
return self.run_model()
File "/usr/local/lib/python3.10/site-packages/behave/runner.py", line 626, in run_model
failed = feature.run(self)
File "/usr/local/lib/python3.10/site-packages/behave/model.py", line 350, in run
formatter.eof()
File "/usr/local/src/behave-xray/src/behave_xray/formatter.py", line 141, in eof
self.xray_publisher.publish(self.test_execution.as_dict())
File "/usr/local/src/behave-xray/src/behave_xray/xray_publisher.py", line 56, in publish
result = self.publish_xray_results(self.endpoint_url, self.auth, test_execution)
File "/usr/local/src/behave-xray/src/behave_xray/xray_publisher.py", line 46, in publish_xray_results
if 'error' in response.json():
File "/usr/local/lib/python3.10/site-packages/requests/models.py", line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

yaml file -

  • export XRAY_API_BASE_URL="https://xray.cloud.getxray.app"
    • export XRAY_CLIENT_ID=${PRJ_XRAY_CLIENT_ID}
    • export XRAY_CLIENT_SECRET=${PRJ_XRAY_CLIENT_SECRET}
    • export token=$(curl -H "Content-Type:application/json" -X POST --data "{"client_id":"$XRAY_CLIENT_ID","client_secret":"$XRAY_CLIENT_SECRET"}" https://xray.cloud.getxray.app/api/v2/authenticate| tr -d '"')
    • echo $token
    • export XRAY_TOKEN=$token
    • behave -f allure -o report/allure/allure-results --f xray ./test/feature/

@kconkas
Copy link
Contributor

kconkas commented Oct 18, 2022

@fundakol I experienced the same issue using Jira Cloud and have traced it down to /api/v2/authenticate endpoint returning an access token surrounded by double quotes. The following solved the issue:

diff --git a/src/behave_xray/bearer_auth.py b/src/behave_xray/bearer_auth.py
index d963fef..57bd8a3 100644
--- a/src/behave_xray/bearer_auth.py
+++ b/src/behave_xray/bearer_auth.py
@@ -42,6 +42,6 @@ class BearerAuth(AuthBase):
             _logger.exception(err_message)
             raise XrayError(err_message) from exc
         else:
-            auth_token = response.text
+            auth_token = response.text.strip('"')
             r.headers['Authorization'] = f'Bearer {auth_token}'
         return r

I don't know if this was because of something peculiar in my organisation's setup though, given that this worked for you.

@fundakol
Copy link
Owner

Thanks @kconkas for point this out, I will fix it.

@BlacktoBlue
Copy link

@fundakol has this issue been resolved yet?

@fundakol
Copy link
Owner

@BlacktoBlue did you observe the issue? If so can you provide some details like what authentication you are using, and it is Jira cloud or not?

@BlacktoBlue
Copy link

I have managed to get a different error than this:
I have only set:
XRAY_API_BASE_URL
XRAY_CLIENT_ID
and
XRAY_CLIENT_SECRET

Exception KeyError: 'key' Traceback (most recent call last): File "C:\Python310\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Python310\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "D:\git\testing\windows-application-framework\venv\Scripts\behave.exe\__main__.py", line 7, in <module> File "D:\git\testing\windows-application-framework\venv\lib\site-packages\behave\__main__.py", line 183, in main return run_behave(config) File "D:\git\testing\windows-application-framework\venv\lib\site-packages\behave\__main__.py", line 127, in run_behave failed = runner.run() File "D:\git\testing\windows-application-framework\venv\lib\site-packages\behave\runner.py", line 804, in run return self.run_with_paths() File "D:\git\testing\windows-application-framework\venv\lib\site-packages\behave\runner.py", line 824, in run_with_paths return self.run_model() File "D:\git\testing\windows-application-framework\venv\lib\site-packages\behave\runner.py", line 626, in run_model failed = feature.run(self) File "D:\git\testing\windows-application-framework\venv\lib\site-packages\behave\model.py", line 350, in run formatter.eof() File "D:\git\testing\windows-application-framework\venv\lib\site-packages\behave_xray\formatter.py", line 223, in eof self.xray_publisher.publish(self.test_execution.as_dict()) File "D:\git\testing\windows-application-framework\venv\lib\site-packages\behave_xray\xray_publisher.py", line 68, in publish key = result['testExecIssue']['key'] if 'testExecIssue' in result else result['key'] KeyError: 'key'

I believe that the authentication is working in v0.2.0, as I initally started with the wrong url, and now that is corrected it seems to be going to the xray api.

@BlacktoBlue
Copy link

Ignore the above this is now all working fine. I had selected the wrong item in Jira for the scenario to be linked to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants