Added change-password test
This commit is contained in:
@@ -17,6 +17,9 @@ class BearerSession():
|
|||||||
def setToken(self,token):
|
def setToken(self,token):
|
||||||
self.headers = {"Authorization": f"Bearer {token}"}
|
self.headers = {"Authorization": f"Bearer {token}"}
|
||||||
|
|
||||||
|
def unsetToken(self):
|
||||||
|
self.headers = {}
|
||||||
|
|
||||||
class FiregexAPI:
|
class FiregexAPI:
|
||||||
def __init__(self,address):
|
def __init__(self,address):
|
||||||
self.s = BearerSession()
|
self.s = BearerSession()
|
||||||
@@ -31,8 +34,16 @@ class FiregexAPI:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def logout(self):
|
def logout(self):
|
||||||
req = self.s.get(f"{self.address}api/logout")
|
self.s.unsetToken()
|
||||||
return req.json()["status"] == "ok"
|
return True
|
||||||
|
|
||||||
|
def change_password(self,password,expire):
|
||||||
|
req = self.s.post(f"{self.address}api/change-password", json={"password":password, "expire":expire})
|
||||||
|
try:
|
||||||
|
self.s.setToken(req.json()["access_token"])
|
||||||
|
return True
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
|
|
||||||
def create_service(self,service_name,service_port):
|
def create_service(self,service_name,service_port):
|
||||||
req = self.s.post(f"{self.address}api/services/add" , json={"name":service_name,"port":service_port})
|
req = self.s.post(f"{self.address}api/services/add" , json={"name":service_name,"port":service_port})
|
||||||
|
|||||||
@@ -40,6 +40,14 @@ service_created = False
|
|||||||
if (firegex.login(args.password)): puts(f"Sucessfully logged in ✔", color=colors.green)
|
if (firegex.login(args.password)): puts(f"Sucessfully logged in ✔", color=colors.green)
|
||||||
else: puts(f"Test Failed: Unknown response or wrong passowrd ✗", color=colors.red); exit(1)
|
else: puts(f"Test Failed: Unknown response or wrong passowrd ✗", color=colors.red); exit(1)
|
||||||
|
|
||||||
|
#Change password
|
||||||
|
new_password = secrets.token_hex(10)
|
||||||
|
if (firegex.change_password(new_password,True)): puts(f"Sucessfully changed password to {new_password} ✔", color=colors.green)
|
||||||
|
else: puts(f"Test Failed: Coundl't change the password ✗", color=colors.red); exit(1)
|
||||||
|
#Changed it back
|
||||||
|
if (firegex.change_password(args.password,True)): puts(f"Sucessfully restored the password ✔", color=colors.green)
|
||||||
|
else: puts(f"Test Failed: Coundl't change the password ✗", color=colors.red); exit(1)
|
||||||
|
|
||||||
|
|
||||||
#Create new Service
|
#Create new Service
|
||||||
if (firegex.create_service(args.service_name,args.service_port)):
|
if (firegex.create_service(args.service_name,args.service_port)):
|
||||||
|
|||||||
Reference in New Issue
Block a user