Skip to content

Commit d762195

Browse files
author
Shakeel Mohamed
committed
Merge branch 'bugfix/DVPL-7026' into develop
2 parents 210fc4c + 9aedf90 commit d762195

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-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: %s\r\n" % self.service.token
1940+
cookie_or_auth_header = "Authorization: Splunk %s\r\n" % \
1941+
(self.service.token if self.service.token is _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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,18 @@ 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+
s = client.connect(**{'token': self.service.token.replace("Splunk ", "")})
107+
i = s.indexes[self.index_name]
108+
event_count = int(i['totalEventCount'])
109+
if s.has_cookies():
110+
del s.http._cookies
111+
cn = i.attach()
112+
cn.send("Hello Boris 5!\r\n")
113+
cn.close()
114+
self.assertEventuallyTrue(lambda: self.totalEventCount() == event_count+1, timeout=60)
115+
104116
def test_submit_via_attached_socket(self):
105117
event_count = int(self.index['totalEventCount'])
106118
f = self.index.attached_socket

0 commit comments

Comments
 (0)