Skip to content

Commit 0f3effd

Browse files
fix(ui): use the correct OAuth2 url (#1899)
**Issue number:** ADDON-82672 ### PR Type **What kind of change does this PR introduce?** * [ ] Feature * [x] Bug Fix * [ ] Refactoring (no functional or API changes) * [ ] Documentation Update * [ ] Maintenance (dependency updates, CI, etc.) ## Summary ### Changes The UI by default uses a different URL for OAuth2 endpoint that UCC generates. Meaning that we get 404 with a TA generated by UCC, without any manual modifications. This PR also adds tests for the previously untested functionality. ### User experience No 404's for `*_oauth` endpoint. ## Checklist If an item doesn't apply to your changes, leave it unchecked. ### Review * [x] self-review - I have performed a self-review of this change according to the [development guidelines](https://splunk.github.io/addonfactory-ucc-generator/contributing/#development-guidelines) * [ ] Changes are documented. The documentation is understandable, examples work [(more info)](https://splunk.github.io/addonfactory-ucc-generator/contributing/#documentation-guidelines) * [x] PR title and description follows the [contributing principles](https://splunk.github.io/addonfactory-ucc-generator/contributing/#pull-requests) * [ ] meeting - I have scheduled a meeting or recorded a demo to explain these changes (if there is a video, put a link below and in the ticket) ### Tests See [the testing doc](https://splunk.github.io/addonfactory-ucc-generator/contributing/#build-and-test). * [x] Unit - tests have been added/modified to cover the changes * [x] Smoke - tests have been added/modified to cover the changes * [x] UI - tests have been added/modified to cover the changes * [x] coverage - I have checked the code coverage of my changes [(see more)](https://splunk.github.io/addonfactory-ucc-generator/contributing/#checking-the-code-coverage) **Demo/meeting:** *Reviewers are encouraged to request meetings or demos if any part of the change is unclear*
1 parent 02b31a5 commit 0f3effd

File tree

16 files changed

+664
-28
lines changed

16 files changed

+664
-28
lines changed

.github/workflows/build-test-release.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,16 @@ jobs:
285285
with:
286286
name: test-results-ui-${{ matrix.splunk.version }}-${{ matrix.test-group }}
287287
path: test-results/*
288+
- name: Copy splunkd.log
289+
if: failure()
290+
run: |
291+
docker cp splunk:/opt/splunk/var/log/splunk/splunkd.log ./splunkd.log
292+
- name: Upload splunkd.log to GitHub Check
293+
uses: actions/upload-artifact@v4
294+
if: failure()
295+
with:
296+
name: test-ui-splunkd-splunkd-${{ matrix.splunk.version }}-${{ matrix.test-group }}.log
297+
path: ./splunkd.log
288298
- uses: dorny/test-reporter@v2
289299
if: success() || failure()
290300
with:

scripts/run_splunk.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ docker run \
2828
-p 8088:8088 \
2929
-p 8089:8089 \
3030
-p 9997:9997 \
31+
--add-host host.docker.internal:host-gateway \
3132
-e "SPLUNK_START_ARGS=--accept-license" \
3233
-e "SPLUNK_PASSWORD=Chang3d!" \
3334
-e "SPLUNK_HEC_TOKEN=4a8a737d-5452-426c-a6f7-106dca4e813f" \

splunk_add_on_ucc_framework/templates/oauth.template

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@ This module will be used to get oauth token from auth code
33
"""
44
import import_declare_test
55

6-
import urllib
7-
try:
8-
from urllib import urlencode
9-
except:
10-
from urllib.parse import urlencode
6+
import json
117
from httplib2 import Http, ProxyInfo, socks
12-
import splunk.admin as admin
8+
from urllib.parse import urlencode, urlsplit
9+
1310
from solnlib import log
1411
from solnlib import conf_manager
1512
from solnlib.conf_manager import InvalidHostnameError, InvalidPortError
1613
from solnlib.utils import is_true
17-
import json
14+
import splunk.admin as admin
15+
from splunk.rest import getcontext
1816

1917

2018
log.Logs.set_context()
@@ -85,7 +83,8 @@ class {{app_name | lower}}_rh_oauth2_token(admin.MConfigHandler):
8583
logger.debug("oAUth url %s", url)
8684
proxy_info = self.getProxyDetails()
8785

88-
http = Http(proxy_info=proxy_info)
86+
context = getcontext(urlsplit(url))
87+
http = Http(proxy_info=proxy_info, context=context)
8988
method = self.callerArgs.data['method'][0]
9089

9190
# Create payload from the arguments received

tests/testdata/expected_addons/expected_output_global_config_configuration/Splunk_TA_UCCExample/bin/splunk_ta_uccexample_rh_oauth.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@
33
"""
44
import import_declare_test
55

6-
import urllib
7-
try:
8-
from urllib import urlencode
9-
except:
10-
from urllib.parse import urlencode
6+
import json
117
from httplib2 import Http, ProxyInfo, socks
12-
import splunk.admin as admin
8+
from urllib.parse import urlencode, urlsplit
9+
1310
from solnlib import log
1411
from solnlib import conf_manager
1512
from solnlib.conf_manager import InvalidHostnameError, InvalidPortError
1613
from solnlib.utils import is_true
17-
import json
14+
import splunk.admin as admin
15+
from splunk.rest import getcontext
1816

1917

2018
log.Logs.set_context()
@@ -85,7 +83,8 @@ def handleEdit(self, confInfo):
8583
logger.debug("oAUth url %s", url)
8684
proxy_info = self.getProxyDetails()
8785

88-
http = Http(proxy_info=proxy_info)
86+
context = getcontext(urlsplit(url))
87+
http = Http(proxy_info=proxy_info, context=context)
8988
method = self.callerArgs.data['method'][0]
9089

9190
# Create payload from the arguments received

tests/testdata/expected_addons/expected_output_global_config_everything/Splunk_TA_UCCExample/bin/splunk_ta_uccexample_rh_oauth.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,16 @@
33
"""
44
import import_declare_test
55

6-
import urllib
7-
try:
8-
from urllib import urlencode
9-
except:
10-
from urllib.parse import urlencode
6+
import json
117
from httplib2 import Http, ProxyInfo, socks
12-
import splunk.admin as admin
8+
from urllib.parse import urlencode, urlsplit
9+
1310
from solnlib import log
1411
from solnlib import conf_manager
1512
from solnlib.conf_manager import InvalidHostnameError, InvalidPortError
1613
from solnlib.utils import is_true
17-
import json
14+
import splunk.admin as admin
15+
from splunk.rest import getcontext
1816

1917

2018
log.Logs.set_context()
@@ -85,7 +83,8 @@ def handleEdit(self, confInfo):
8583
logger.debug("oAUth url %s", url)
8684
proxy_info = self.getProxyDetails()
8785

88-
http = Http(proxy_info=proxy_info)
86+
context = getcontext(urlsplit(url))
87+
http = Http(proxy_info=proxy_info, context=context)
8988
method = self.callerArgs.data['method'][0]
9089

9190
# Create payload from the arguments received

tests/testdata/expected_addons/expected_output_global_config_everything/Splunk_TA_UCCExample/bin/splunk_ta_uccexample_rh_organization.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,14 @@
4949
encrypted=False,
5050
default=None,
5151
validator=None
52-
),
52+
),
53+
field.RestField(
54+
'endpoint',
55+
required=False,
56+
encrypted=False,
57+
default=None,
58+
validator=None
59+
),
5360
field.RestField(
5461
'access_token',
5562
required=False,

tests/testdata/test_addons/package_global_config_everything/globalConfig.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -748,10 +748,16 @@
748748
"label": "Redirect url",
749749
"field": "redirect_url",
750750
"help": "Copy and paste this URL into your app."
751+
},
752+
{
753+
"oauth_field": "endpoint",
754+
"label": "Endpoint",
755+
"field": "endpoint",
756+
"help": "Put here endpoint, ie. login.salesforce.com"
751757
}
752758
],
753-
"auth_code_endpoint": "/services/oauth2/authorize",
754-
"access_token_endpoint": "/services/oauth2/token",
759+
"auth_code_endpoint": "/oauth/authorize",
760+
"access_token_endpoint": "/oauth/token",
755761
"oauth_timeout": 30,
756762
"oauth_state_enabled": false
757763
}

tests/ui/conftest.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import pytest
44

5+
from tests.ui.oauth2_server.oauth_server import OAuth2TestServer
56
from tests.ui.pages.account_page import AccountPage
67
from tests.ui.test_configuration_page_account_tab import _ACCOUNT_CONFIG
78
from pytest_splunk_addon_ui_smartx import utils as s_utils
@@ -53,3 +54,19 @@ def pytest_runtest_call(item: pytest.Item) -> Iterator[Any]:
5354
log_msg = [f"{log.level}: {log.source} - {log.message}" for log in severe_logs]
5455
msg = "Severe logs found in browser console logs: \n" + "\n".join(log_msg)
5556
pytest.fail(msg, pytrace=True)
57+
58+
59+
@pytest.fixture(scope="session")
60+
def _oauth_server() -> Iterator[OAuth2TestServer]:
61+
"""Pytest fixture for OAuth2 test server."""
62+
server = OAuth2TestServer(host="0.0.0.0") # Use random port
63+
server.start()
64+
yield server
65+
server.stop()
66+
67+
68+
@pytest.fixture
69+
def oauth_server_port(_oauth_server: OAuth2TestServer) -> int:
70+
"""Pytest fixture for OAuth2 test server."""
71+
_oauth_server.clear_data()
72+
return _oauth_server.port

tests/ui/oauth2_server/__init__.py

Whitespace-only changes.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>OAuth2 Test Server - Login</title>
5+
<style>
6+
body { font-family: Arial, sans-serif; margin: 50px; }
7+
.form-container { max-width: 400px; margin: 0 auto; }
8+
.form-group { margin: 15px 0; }
9+
label { display: block; margin-bottom: 5px; }
10+
input { width: 100%; padding: 8px; box-sizing: border-box; }
11+
button { background-color: #007cba; color: white; padding: 10px 20px; border: none; cursor: pointer; }
12+
button:hover { background-color: #005a87; }
13+
.info { background-color: #f0f0f0; padding: 15px; margin-bottom: 20px; border-radius: 5px; }
14+
</style>
15+
</head>
16+
<body>
17+
<div class="form-container">
18+
<h2>OAuth2 Test Server</h2>
19+
<div class="info">
20+
<strong>Test Credentials:</strong><br>
21+
Email: Any email address<br>
22+
Password: <code>good</code>
23+
</div>
24+
<form method="post" action="/oauth/authorize">
25+
<input type="hidden" name="client_id" value="${client_id}">
26+
<input type="hidden" name="redirect_uri" value="${redirect_uri}">
27+
<input type="hidden" name="state" value="${state}">
28+
<input type="hidden" name="response_type" value="${response_type}">
29+
30+
<div class="form-group">
31+
<label for="email">Email:</label>
32+
<input type="email" id="email" name="email" required>
33+
</div>
34+
35+
<div class="form-group">
36+
<label for="password">Password:</label>
37+
<input type="password" id="password" name="password" required>
38+
</div>
39+
40+
<div class="form-group">
41+
<button type="submit">Login</button>
42+
</div>
43+
</form>
44+
</div>
45+
</body>
46+
</html>

0 commit comments

Comments
 (0)