28 lines
1.1 KiB
Python
28 lines
1.1 KiB
Python
import json
|
|
|
|
def simulate_normalize_signal(raw_json, approved_id):
|
|
data = json.loads(raw_json)
|
|
sender = data.get("source")
|
|
text = data.get("message")
|
|
|
|
if sender == approved_id:
|
|
return {"type": "EVENT", "payload": {"sensor": "inbound-message", "channel": "signal", "text": text}}
|
|
return None
|
|
|
|
if __name__ == "__main__":
|
|
approved_id = "+1234567890"
|
|
|
|
print("--- Test 1: Authorized Signal Message ---")
|
|
valid_payload = json.dumps({"source": "+1234567890", "message": "Hello Agent"})
|
|
res1 = simulate_normalize_signal(valid_payload, approved_id)
|
|
print(f"Result: {res1}")
|
|
status1 = "PASS" if res1 and res1["payload"]["text"] == "Hello Agent" else "FAIL"
|
|
|
|
print("\n--- Test 2: Unauthorized Signal Message ---")
|
|
malicious_payload = json.dumps({"source": "+9999999999", "message": "I am evil"})
|
|
res2 = simulate_normalize_signal(malicious_payload, approved_id)
|
|
print(f"Result: {res2}")
|
|
status2 = "PASS" if res2 is None else "FAIL"
|
|
|
|
print(f"\nFinal Status: {'PASS' if status1 == 'PASS' and status2 == 'PASS' else 'FAIL'}")
|