Skip to content

Commit 06d28fd

Browse files
author
Shakeel Mohamed
committed
Fix broken tests
1 parent 8fdf60c commit 06d28fd

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

splunklib/client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
import socket
6868
import contextlib
6969

70-
from binding import Context, HTTPError, AuthenticationError, namespace, UrlEncoded, _encode, _make_cookie_header
70+
from binding import Context, HTTPError, AuthenticationError, namespace, UrlEncoded, _encode, _make_cookie_header, _NoAuthenticationToken
7171
from data import record
7272
import data
7373

@@ -1937,7 +1937,9 @@ def attach(self, host=None, source=None, sourcetype=None):
19371937
if sourcetype is not None: args['sourcetype'] = sourcetype
19381938
path = UrlEncoded(PATH_RECEIVERS_STREAM + "?" + urllib.urlencode(args), skip_encode=True)
19391939

1940-
cookie_or_auth_header = "Authorization: Splunk %s\r\n" % self.service.token.replace('Splunk ','')
1940+
cookie_or_auth_header = "Authorization: Splunk %s\r\n" % \
1941+
self.service.token if isinstance(self.service.token, _NoAuthenticationToken) \
1942+
else self.service.token.replace("Splunk ", "")
19411943

19421944
# If we have cookie(s), use them instead of "Authorization: ..."
19431945
if self.service.has_cookies():

tests/test_index.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,17 @@ def test_submit_via_attach(self):
101101
cn.close()
102102
self.assertEventuallyTrue(lambda: self.totalEventCount() == event_count+1, timeout=60)
103103

104+
def test_submit_via_attach_using_token_header(self):
105+
# Remove the prefix from the token
106+
token = self.service.token.replace("Splunk: ", "")
107+
s = client.Service(**{token: token})
108+
i = s.indexes[self.index_name]
109+
event_count = int(i['totalEventCount'])
110+
cn = i.attach()
111+
cn.send("Hello Boris!\r\n")
112+
cn.close()
113+
self.assertEventuallyTrue(lambda: self.totalEventCount() == event_count+1, timeout=60)
114+
104115
def test_submit_via_attached_socket(self):
105116
event_count = int(self.index['totalEventCount'])
106117
f = self.index.attached_socket

0 commit comments

Comments
 (0)