Skip to content

Commit

Permalink
Merge branch 'bugfix/DVPL-7026' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Shakeel Mohamed committed Nov 22, 2016
2 parents 210fc4c + 9aedf90 commit d762195
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 4 additions & 2 deletions splunklib/client.py
Expand Up @@ -67,7 +67,7 @@
import socket
import contextlib

from binding import Context, HTTPError, AuthenticationError, namespace, UrlEncoded, _encode, _make_cookie_header
from binding import Context, HTTPError, AuthenticationError, namespace, UrlEncoded, _encode, _make_cookie_header, _NoAuthenticationToken
from data import record
import data

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

cookie_or_auth_header = "Authorization: %s\r\n" % self.service.token
cookie_or_auth_header = "Authorization: Splunk %s\r\n" % \
(self.service.token if self.service.token is _NoAuthenticationToken
else self.service.token.replace("Splunk ", ""))

# If we have cookie(s), use them instead of "Authorization: ..."
if self.service.has_cookies():
Expand Down
12 changes: 12 additions & 0 deletions tests/test_index.py
Expand Up @@ -101,6 +101,18 @@ def test_submit_via_attach(self):
cn.close()
self.assertEventuallyTrue(lambda: self.totalEventCount() == event_count+1, timeout=60)

def test_submit_via_attach_using_token_header(self):
# Remove the prefix from the token
s = client.connect(**{'token': self.service.token.replace("Splunk ", "")})
i = s.indexes[self.index_name]
event_count = int(i['totalEventCount'])
if s.has_cookies():
del s.http._cookies
cn = i.attach()
cn.send("Hello Boris 5!\r\n")
cn.close()
self.assertEventuallyTrue(lambda: self.totalEventCount() == event_count+1, timeout=60)

def test_submit_via_attached_socket(self):
event_count = int(self.index['totalEventCount'])
f = self.index.attached_socket
Expand Down

0 comments on commit d762195

Please sign in to comment.