|
1 |
| -// Copyright (c) 2016 Tigera, Inc. All rights reserved. |
| 1 | +// Copyright (c) 2016-2017 Tigera, Inc. All rights reserved. |
2 | 2 |
|
3 | 3 | // Licensed under the Apache License, Version 2.0 (the "License");
|
4 | 4 | // you may not use this file except in compliance with the License.
|
@@ -52,6 +52,8 @@ func init() {
|
52 | 52 | netv6_3 := testutils.MustParseNetwork("aabb:aabb::ffff/122")
|
53 | 53 | netv6_4 := testutils.MustParseNetwork("aabb:aabb::ffff/10")
|
54 | 54 |
|
| 55 | + protoTCP := numorstring.ProtocolFromString("tcp") |
| 56 | + |
55 | 57 | // Perform basic validation of different fields and structures to test simple valid/invalid
|
56 | 58 | // scenarios. This does not test precise error strings - but does cover a lot of the validation
|
57 | 59 | // code paths.
|
@@ -88,6 +90,24 @@ func init() {
|
88 | 90 | Entry("should accept IP version 6 (m)", model.Rule{IPVersion: &V6}, true),
|
89 | 91 | Entry("should reject IP version 0 (m)", model.Rule{IPVersion: &V0}, false),
|
90 | 92 |
|
| 93 | + // (Backend model) Ports. |
| 94 | + Entry("should accept ports with tcp protocol (m)", model.Rule{ |
| 95 | + Protocol: &protoTCP, |
| 96 | + SrcPorts: []numorstring.Port{numorstring.SinglePort(80)}, |
| 97 | + }, true), |
| 98 | + Entry("should reject src ports with no protocol (m)", model.Rule{ |
| 99 | + SrcPorts: []numorstring.Port{numorstring.SinglePort(80)}, |
| 100 | + }, false), |
| 101 | + Entry("should reject dst ports with no protocol (m)", model.Rule{ |
| 102 | + DstPorts: []numorstring.Port{numorstring.SinglePort(80)}, |
| 103 | + }, false), |
| 104 | + Entry("should reject !src ports with no protocol (m)", model.Rule{ |
| 105 | + NotSrcPorts: []numorstring.Port{numorstring.SinglePort(80)}, |
| 106 | + }, false), |
| 107 | + Entry("should reject !dst ports with no protocol (m)", model.Rule{ |
| 108 | + NotDstPorts: []numorstring.Port{numorstring.SinglePort(80)}, |
| 109 | + }, false), |
| 110 | + |
91 | 111 | // (API) IP version.
|
92 | 112 | Entry("should accept IP version 4", api.Rule{Action: "allow", IPVersion: &V4}, true),
|
93 | 113 | Entry("should accept IP version 6", api.Rule{Action: "allow", IPVersion: &V6}, true),
|
@@ -350,6 +370,13 @@ func init() {
|
350 | 370 | Ports: []numorstring.Port{numorstring.SinglePort(1)},
|
351 | 371 | },
|
352 | 372 | }, true),
|
| 373 | + Entry("should reject Rule with dest ports and no protocol", |
| 374 | + api.Rule{ |
| 375 | + Action: "allow", |
| 376 | + Destination: api.EntityRule{ |
| 377 | + Ports: []numorstring.Port{numorstring.SinglePort(1)}, |
| 378 | + }, |
| 379 | + }, false), |
353 | 380 | Entry("should reject Rule with invalid port (port 0)",
|
354 | 381 | api.Rule{
|
355 | 382 | Action: "allow",
|
|
0 commit comments