Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Coredns
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
Coredns
Commits
9b3b2679
Commit
9b3b2679
authored
Aug 31, 2021
by
Chris O'Haver
Committed by
GitHub
Aug 31, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
restore 1.8.3 question revert logic; add tests (#4840)
Signed-off-by:
Chris O'Haver
<
cohaver@infoblox.com
>
parent
b143cd49
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
1 deletion
+57
-1
plugin/rewrite/rewrite.go
plugin/rewrite/rewrite.go
+4
-1
plugin/rewrite/rewrite_test.go
plugin/rewrite/rewrite_test.go
+53
-0
No files found.
plugin/rewrite/rewrite.go
View file @
9b3b2679
...
...
@@ -54,7 +54,10 @@ func (rw Rewrite) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg
}
wr
.
ResponseRules
=
append
(
wr
.
ResponseRules
,
respRules
...
)
if
rule
.
Mode
()
==
Stop
{
break
if
!
rw
.
RevertPolicy
.
DoRevert
()
{
return
plugin
.
NextOrFailure
(
rw
.
Name
(),
rw
.
Next
,
ctx
,
w
,
r
)
}
return
plugin
.
NextOrFailure
(
rw
.
Name
(),
rw
.
Next
,
ctx
,
wr
,
r
)
}
}
}
...
...
plugin/rewrite/rewrite_test.go
View file @
9b3b2679
...
...
@@ -163,6 +163,59 @@ func TestNewRule(t *testing.T) {
}
}
func
TestRewriteDefaultRevertPolicy
(
t
*
testing
.
T
)
{
rules
:=
[]
Rule
{}
r
,
_
:=
newNameRule
(
"stop"
,
"prefix"
,
"prefix"
,
"to"
)
rules
=
append
(
rules
,
r
)
r
,
_
=
newNameRule
(
"stop"
,
"suffix"
,
".suffix."
,
".nl."
)
rules
=
append
(
rules
,
r
)
r
,
_
=
newNameRule
(
"stop"
,
"substring"
,
"from.substring"
,
"to"
)
rules
=
append
(
rules
,
r
)
r
,
_
=
newNameRule
(
"stop"
,
"regex"
,
"(f.*m)
\\
.regex
\\
.(nl)"
,
"to.{2}"
)
rules
=
append
(
rules
,
r
)
rw
:=
Rewrite
{
Next
:
plugin
.
HandlerFunc
(
msgPrinter
),
Rules
:
rules
,
// use production (default) RevertPolicy
}
tests
:=
[]
struct
{
from
string
fromT
uint16
fromC
uint16
to
string
toT
uint16
toC
uint16
}{
{
"prefix.nl."
,
dns
.
TypeA
,
dns
.
ClassINET
,
"to.nl."
,
dns
.
TypeA
,
dns
.
ClassINET
},
{
"to.suffix."
,
dns
.
TypeA
,
dns
.
ClassINET
,
"to.nl."
,
dns
.
TypeA
,
dns
.
ClassINET
},
{
"from.substring.nl."
,
dns
.
TypeA
,
dns
.
ClassINET
,
"to.nl."
,
dns
.
TypeA
,
dns
.
ClassINET
},
{
"from.regex.nl."
,
dns
.
TypeA
,
dns
.
ClassINET
,
"to.nl."
,
dns
.
TypeA
,
dns
.
ClassINET
},
}
ctx
:=
context
.
TODO
()
for
i
,
tc
:=
range
tests
{
m
:=
new
(
dns
.
Msg
)
m
.
SetQuestion
(
tc
.
from
,
tc
.
fromT
)
m
.
Question
[
0
]
.
Qclass
=
tc
.
fromC
rec
:=
dnstest
.
NewRecorder
(
&
test
.
ResponseWriter
{})
rw
.
ServeDNS
(
ctx
,
rec
,
m
)
resp
:=
rec
.
Msg
if
resp
.
Question
[
0
]
.
Name
!=
tc
.
from
{
t
.
Errorf
(
"Test %d: Expected Name in Question to be %q but was %q"
,
i
,
tc
.
from
,
resp
.
Question
[
0
]
.
Name
)
}
if
resp
.
Answer
[
0
]
.
Header
()
.
Name
!=
tc
.
to
{
t
.
Errorf
(
"Test %d: Expected Name in Answer to be %q but was %q"
,
i
,
tc
.
to
,
resp
.
Answer
[
0
]
.
Header
()
.
Name
)
}
}
}
func
TestRewrite
(
t
*
testing
.
T
)
{
rules
:=
[]
Rule
{}
r
,
_
:=
newNameRule
(
"stop"
,
"from.nl."
,
"to.nl."
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment