(t *testing.T)
| 784 | } |
| 785 | |
| 786 | func TestInboundValidity(t *testing.T) { //nolint:cyclop |
| 787 | defer test.CheckRoutines(t)() |
| 788 | |
| 789 | buildMsg := func(class stun.MessageClass, username, key string) *stun.Message { |
| 790 | msg, err := stun.Build(stun.NewType(stun.MethodBinding, class), stun.TransactionID, |
| 791 | stun.NewUsername(username), |
| 792 | stun.NewShortTermIntegrity(key), |
| 793 | stun.Fingerprint, |
| 794 | ) |
| 795 | require.NoError(t, err) |
| 796 | |
| 797 | return msg |
| 798 | } |
| 799 | |
| 800 | remote := &net.UDPAddr{IP: net.ParseIP("172.17.0.3"), Port: 999} |
| 801 | hostConfig := CandidateHostConfig{ |
| 802 | Network: "udp", |
| 803 | Address: "192.168.0.2", |
| 804 | Port: 777, |
| 805 | Component: 1, |
| 806 | } |
| 807 | local, err := NewCandidateHost(&hostConfig) |
| 808 | local.conn = &fakenet.MockPacketConn{} |
| 809 | require.NoError(t, err) |
| 810 | |
| 811 | t.Run("Invalid Binding requests should be discarded", func(t *testing.T) { |
| 812 | agent, err := NewAgent(&AgentConfig{}) |
| 813 | require.NoError(t, err) |
| 814 | defer func() { |
| 815 | require.NoError(t, agent.Close()) |
| 816 | }() |
| 817 | |
| 818 | agent.handleInbound(buildMsg(stun.ClassRequest, "invalid", agent.localPwd), local, remote) |
| 819 | require.Len(t, agent.remoteCandidates, 0) |
| 820 | |
| 821 | agent.handleInbound(buildMsg(stun.ClassRequest, agent.localUfrag+":"+agent.remoteUfrag, "Invalid"), local, remote) |
| 822 | require.Len(t, agent.remoteCandidates, 0) |
| 823 | }) |
| 824 | |
| 825 | t.Run("Invalid Binding success responses should be discarded", func(t *testing.T) { |
| 826 | a, err := NewAgent(&AgentConfig{}) |
| 827 | require.NoError(t, err) |
| 828 | defer func() { |
| 829 | require.NoError(t, a.Close()) |
| 830 | }() |
| 831 | |
| 832 | a.handleInbound(buildMsg(stun.ClassSuccessResponse, a.localUfrag+":"+a.remoteUfrag, "Invalid"), local, remote) |
| 833 | require.Len(t, a.remoteCandidates, 0) |
| 834 | }) |
| 835 | |
| 836 | t.Run("Discard non-binding messages", func(t *testing.T) { |
| 837 | a, err := NewAgent(&AgentConfig{}) |
| 838 | require.NoError(t, err) |
| 839 | defer func() { |
| 840 | require.NoError(t, a.Close()) |
| 841 | }() |
| 842 | |
| 843 | a.handleInbound(buildMsg(stun.ClassErrorResponse, a.localUfrag+":"+a.remoteUfrag, "Invalid"), local, remote) |
nothing calls this directly
no test coverage detected
searching dependent graphs…