12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- package main
- import (
- "testing"
- )
- func TestAddrAllowedNoDomain(t *testing.T) {
- allowedAddrs := []string{"[email protected]"}
- if addrAllowed("bob.com", allowedAddrs) {
- t.FailNow()
- }
- }
- func TestAddrAllowedSingle(t *testing.T) {
- allowedAddrs := []string{"[email protected]"}
- if !addrAllowed("[email protected]", allowedAddrs) {
- t.FailNow()
- }
- if addrAllowed("[email protected]", allowedAddrs) {
- t.FailNow()
- }
- }
- func TestAddrAllowedDifferentCase(t *testing.T) {
- allowedAddrs := []string{"[email protected]"}
- testAddrs := []string{
- "[email protected]",
- "[email protected]",
- "[email protected]",
- "[email protected]",
- }
- for _, addr := range testAddrs {
- if !addrAllowed(addr, allowedAddrs) {
- t.Errorf("Address %v not allowed, but should be", addr)
- }
- }
- }
- func TestAddrAllowedLocal(t *testing.T) {
- allowedAddrs := []string{"joe"}
- if !addrAllowed("joe", allowedAddrs) {
- t.FailNow()
- }
- if addrAllowed("bob", allowedAddrs) {
- t.FailNow()
- }
- }
- func TestAddrAllowedMulti(t *testing.T) {
- allowedAddrs := []string{"[email protected]", "[email protected]"}
- if !addrAllowed("[email protected]", allowedAddrs) {
- t.FailNow()
- }
- if !addrAllowed("[email protected]", allowedAddrs) {
- t.FailNow()
- }
- if addrAllowed("[email protected]", allowedAddrs) {
- t.FailNow()
- }
- }
- func TestAddrAllowedSingleDomain(t *testing.T) {
- allowedAddrs := []string{"@abc.com"}
- if !addrAllowed("[email protected]", allowedAddrs) {
- t.FailNow()
- }
- if addrAllowed("[email protected]", allowedAddrs) {
- t.FailNow()
- }
- }
- func TestAddrAllowedMixed(t *testing.T) {
- allowedAddrs := []string{"app", "[email protected]", "@appsrv.example.com"}
- if !addrAllowed("app", allowedAddrs) {
- t.FailNow()
- }
- if !addrAllowed("[email protected]", allowedAddrs) {
- t.FailNow()
- }
- if addrAllowed("[email protected]", allowedAddrs) {
- t.FailNow()
- }
- if !addrAllowed("[email protected]", allowedAddrs) {
- t.FailNow()
- }
- if !addrAllowed("[email protected]", allowedAddrs) {
- t.FailNow()
- }
- if addrAllowed("[email protected]", allowedAddrs) {
- t.FailNow()
- }
- }
|