Skip to content

Commit 9aedf90

Browse files
author
Shakeel Mohamed
committed
Update conditional logic
1 parent 06d28fd commit 9aedf90

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

splunklib/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,8 +1938,8 @@ def attach(self, host=None, source=None, sourcetype=None):
19381938
path = UrlEncoded(PATH_RECEIVERS_STREAM + "?" + urllib.urlencode(args), skip_encode=True)
19391939

19401940
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 ", "")
1941+
(self.service.token if self.service.token is _NoAuthenticationToken
1942+
else self.service.token.replace("Splunk ", ""))
19431943

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

tests/test_index.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,13 @@ def test_submit_via_attach(self):
103103

104104
def test_submit_via_attach_using_token_header(self):
105105
# Remove the prefix from the token
106-
token = self.service.token.replace("Splunk: ", "")
107-
s = client.Service(**{token: token})
106+
s = client.connect(**{'token': self.service.token.replace("Splunk ", "")})
108107
i = s.indexes[self.index_name]
109108
event_count = int(i['totalEventCount'])
109+
if s.has_cookies():
110+
del s.http._cookies
110111
cn = i.attach()
111-
cn.send("Hello Boris!\r\n")
112+
cn.send("Hello Boris 5!\r\n")
112113
cn.close()
113114
self.assertEventuallyTrue(lambda: self.totalEventCount() == event_count+1, timeout=60)
114115

0 commit comments

Comments
 (0)