package dispatcher

import "testing"

func TestEnvelopeValidate(t *testing.T) {
	allowed := map[string]struct{}{"remailer.example": {}}
	valid := Envelope{
		EntryAddress: "entry@remailer.example",
		Message:      []byte("To: entry@remailer.example\nFrom: mix@nowhere.invalid\n\n-----BEGIN REMAILER MESSAGE-----\nabc\n"),
	}
	if err := valid.Validate(allowed); err != nil {
		t.Fatalf("expected valid envelope: %v", err)
	}

	invalidDomain := valid
	invalidDomain.EntryAddress = "entry@other.example"
	invalidDomain.Message = []byte("To: entry@other.example\n-----BEGIN REMAILER MESSAGE-----\n")
	if err := invalidDomain.Validate(allowed); err == nil {
		t.Fatal("expected unknown domain rejection")
	}
}
