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
f51c1105
Commit
f51c1105
authored
Dec 06, 2018
by
Daniel Garcia
Committed by
Miek Gieben
Dec 06, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use TrimPrefix instead of TrimLeft in rewrite prefix plugin (#2364) (#2370)
parent
9a393ac5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
1 deletion
+29
-1
plugin/rewrite/name.go
plugin/rewrite/name.go
+1
-1
plugin/rewrite/name_test.go
plugin/rewrite/name_test.go
+28
-0
No files found.
plugin/rewrite/name.go
View file @
f51c1105
...
...
@@ -71,7 +71,7 @@ func (rule *exactNameRule) Rewrite(ctx context.Context, state request.Request) R
// Rewrite rewrites the current request when the name begins with the matching string.
func
(
rule
*
prefixNameRule
)
Rewrite
(
ctx
context
.
Context
,
state
request
.
Request
)
Result
{
if
strings
.
HasPrefix
(
state
.
Name
(),
rule
.
Prefix
)
{
state
.
Req
.
Question
[
0
]
.
Name
=
rule
.
Replacement
+
strings
.
Trim
Left
(
state
.
Name
(),
rule
.
Prefix
)
state
.
Req
.
Question
[
0
]
.
Name
=
rule
.
Replacement
+
strings
.
Trim
Prefix
(
state
.
Name
(),
rule
.
Prefix
)
return
RewriteDone
}
return
RewriteIgnored
...
...
plugin/rewrite/name_test.go
View file @
f51c1105
...
...
@@ -32,6 +32,34 @@ func TestRewriteIllegalName(t *testing.T) {
}
}
func
TestRewriteNamePrefix
(
t
*
testing
.
T
)
{
r
,
err
:=
newNameRule
(
"stop"
,
"prefix"
,
"test"
,
"not-a-test"
)
if
err
!=
nil
{
t
.
Fatalf
(
"Expected no error, got %s"
,
err
)
}
rw
:=
Rewrite
{
Next
:
plugin
.
HandlerFunc
(
msgPrinter
),
Rules
:
[]
Rule
{
r
},
noRevert
:
true
,
}
ctx
:=
context
.
TODO
()
m
:=
new
(
dns
.
Msg
)
m
.
SetQuestion
(
"test.example.org."
,
dns
.
TypeA
)
rec
:=
dnstest
.
NewRecorder
(
&
test
.
ResponseWriter
{})
_
,
err
=
rw
.
ServeDNS
(
ctx
,
rec
,
m
)
if
err
!=
nil
{
t
.
Fatalf
(
"Expected no error, got %s"
,
err
)
}
expected
:=
"not-a-test.example.org."
actual
:=
rec
.
Msg
.
Question
[
0
]
.
Name
if
actual
!=
expected
{
t
.
Fatalf
(
"Expected rewrite to %v, got %v"
,
expected
,
actual
)
}
}
func
TestNewNameRule
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
next
string
...
...
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