Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions solnlib/splunk_rest_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@

import logging
import os
import sys
import traceback
import solnlib

from io import BytesIO
from urllib.parse import quote
from urllib3.util.retry import Retry

from splunklib import binding, client

from .net_utils import validate_scheme_host_port
Expand Down Expand Up @@ -134,7 +136,7 @@ def request(url, message, **kwargs):

body = message.get("body")
headers = {
"User-Agent": "curl",
"User-Agent": f"solnlib/{solnlib.__version__} rest-client {sys.platform}",
"Accept": "*/*",
"Connection": "Keep-Alive",
}
Expand Down
45 changes: 45 additions & 0 deletions tests/integration/test_splunk_rest_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#
# Copyright 2025 Splunk Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import context
import pytest
import solnlib
import sys
from splunklib import binding
from solnlib import splunk_rest_client as rest_client

from _search import search


def test_rest_client_user_agent():
test_url = r'search index = _internal uri_path="*/servicesNS/nobody/test_app/some/unexisting/url"'
user_agent = f"solnlib/{solnlib.__version__} rest-client {sys.platform}"
session_key = context.get_session_key()
wrong_url = r"some/unexisting/url"
rc = rest_client.SplunkRestClient(
session_key,
app="test_app",
owner=context.owner,
scheme=context.scheme,
host=context.host,
port=context.port,
)
with pytest.raises(binding.HTTPError):
rc.get(wrong_url)

search_results = search(session_key, test_url)
assert len(search_results) == 1
assert user_agent in search_results[0]["_raw"]
Loading