package tencentrtc

import "testing"

func TestVerifyCallbackSignatureUsesRawBody(t *testing.T) {
	body := []byte("{\n\t\"EventGroupId\":\t2,\n\t\"EventType\":\t204,\n\t\"CallbackTs\":\t1664209748188,\n\t\"EventInfo\":\t{\n\t\t\"RoomId\":\t8489,\n\t\t\"EventTs\":\t1664209748,\n\t\t\"EventMsTs\":\t1664209748180,\n\t\t\"UserId\":\t\"user_85034614\",\n\t\t\"Reason\":\t0\n\t}\n}")
	sign := "kkoFeO3Oh2ZHnjtg8tEAQhtXK16/KI05W3BQff8IvGA="

	if !VerifyCallbackSignature("123654", body, sign) {
		t.Fatal("expected official Tencent RTC callback signature sample to verify")
	}
	if VerifyCallbackSignature("123654", []byte(`{"EventType":204}`), sign) {
		t.Fatal("signature verification must use the exact raw callback body")
	}
	if VerifyCallbackSignature("", body, sign) || VerifyCallbackSignature("123654", body, "") {
		t.Fatal("missing key or sign must fail closed")
	}
}
