Skip to content
Merged
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
84 changes: 82 additions & 2 deletions tests/integration/test_rest_handler_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@
from datetime import datetime
from time import sleep
from typing import List, Any
from unittest import expectedFailure
from urllib import parse
from requests.auth import HTTPBasicAuth
from splunktaucclib.rest_handler.handler import BASIC_NAME_VALIDATORS
import requests
import os
from defusedxml import ElementTree

import pytest

admin = os.getenv("SPLUNK_ADMIN")
admin_password = os.getenv("SPLUNK_ADMIN_PWD")
admin = "admin"
admin_password = "Chang3d!"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a temporary change, right? :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to revert it or at least getenv with a default value: os.getenv("SPLUNK_ADMIN", "admin")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, by mistake I pushed my local config :)

user = os.getenv("SPLUNK_USER")
user_password = os.getenv("SPLUNK_USER_PWD")
host = "localhost"
Expand All @@ -48,6 +50,84 @@ def _cookie_header():
return f"splunkd_8000={session_key}"


def test_basic_crud_operations():
input_name = "atest_in_ok"

# CREATE
response = requests.post(
f"https://{host}:{management_port}/servicesNS/-/demo/demo_demo",
data={"name": input_name, "interval": "5"},
headers={
"accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded",
},
auth=HTTPBasicAuth(admin, admin_password),
verify=False,
)
assert response.status_code == 201

# GET
response = requests.get(
f"https://{host}:{management_port}/servicesNS/-/demo/demo_demo/{input_name}",
auth=HTTPBasicAuth(admin, admin_password),
headers={
"accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded",
},
verify=False,
)
assert response.status_code == 200

# ALL
response = requests.get(
f"https://{host}:{management_port}/servicesNS/-/demo/demo_demo/",
auth=HTTPBasicAuth(admin, admin_password),
verify=False,
)
text = response.text
tree = ElementTree.fromstring(text)
entry = [el for el in list(tree) if "entry" in el.tag]
assert response.status_code == 200
assert len(entry) == 2

# UPDATE
response = requests.post(
f"https://{host}:{management_port}/servicesNS/-/demo/demo_demo/{input_name}",
data={"interval": "55"},
auth=HTTPBasicAuth(admin, admin_password),
verify=False,
)
expected_str = '<s:key name="interval">55</s:key>'
assert expected_str in response.text

# DELETE
response = requests.delete(
f"https://{host}:{management_port}/servicesNS/-/demo/demo_demo/{input_name}",
auth=HTTPBasicAuth(admin, admin_password),
verify=False,
)
text = response.text
tree = ElementTree.fromstring(text)
entry = [el for el in list(tree) if "entry" in el.tag]
assert response.status_code == 200
assert len(entry) == 1

expected_msg = (
f"REST Error [404]: Not Found -- Could not find object id={input_name}"
)
response = requests.get(
f"https://{host}:{management_port}/servicesNS/-/demo/demo_demo/{input_name}",
auth=HTTPBasicAuth(admin, admin_password),
headers={
"accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded",
},
verify=False,
)
assert response.status_code == 500
assert expected_msg in response.text


def test_inputs_api_call():
try:
response = requests.get(
Expand Down
Loading