Page Menu
Home
GRNET
Search
Configure Global Search
Log In
Files
F905172
ns_test.rb
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Fri, Aug 29, 9:42 PM
Size
5 KB
Mime Type
text/x-ruby
Expires
Sun, Aug 31, 9:42 PM (9 h, 43 m)
Engine
blob
Format
Raw Data
Handle
252527
Attached To
rWEBDNS WebDNS (edet4)
ns_test.rb
View Options
require
'test_helper'
class
NSTest
<
ActiveSupport
::
TestCase
setup
do
@record
=
build
(
:ns
)
end
test
'save'
do
@record
.
save
assert_empty
@record
.
errors
end
test
'chop terminating dot'
do
@record
.
content
=
'with-dot.example.com.'
@record
.
save!
@record
.
reload
assert_equal
'with-dot.example.com'
,
@record
.
content
end
test
'drop privileges on zone NS records'
do
@record
.
drop_privileges
=
true
@record
.
save
assert_not_empty
@record
.
errors
[
:name
]
end
test
'doesnt drop privileges on non zone NS records'
do
@record
.
name
=
'other'
@record
.
drop_privileges
=
true
@record
.
save
assert_empty
@record
.
errors
[
:name
]
end
class
ClasslessDelegation
<
ActiveSupport
::
TestCase
setup
do
@record
=
build
(
:cd_ns
,
name
:
'192/29'
)
@domain
=
@record
.
domain
end
test
'creates delegation'
do
assert
@record
.
save
assert
@record
.
classless_delegation?
octets
=
[
192
,
193
,
194
,
195
,
196
,
197
,
198
,
199
]
assert_equal
octets
.
size
,
@domain
.
records
.
where
(
type
:
'CNAME'
)
.
count
octets
.
each
{
|
octet
|
cname
=
@domain
.
records
.
where
(
type
:
'CNAME'
,
name
:
"
#{
octet
}
.
#{
@domain
.
name
}
"
)
.
first
assert
cname
,
"
#{
octet
}
delegation"
assert_not
cname
.
editable?
,
"
#{
octet
}
editable"
assert
cname
.
classless_delegated?
,
"
#{
octet
}
classless_delegated"
}
end
test
'delete delegation'
do
assert
@record
.
save
@record
.
destroy
assert_equal
0
,
@domain
.
records
.
where
(
type
:
'CNAME'
)
.
count
,
'zero delegations'
end
[
'0/24'
,
# too big
'0/32'
,
# too small
'191/29'
,
'-192/29'
,
'192/-29'
,
'192/29/29'
,
'192'
,
].
each
{
|
del
|
test
"invalid delegation
#{
del
}
"
do
@record
.
name
=
del
@record
.
save!
assert_not
@record
.
classless_delegation?
assert_equal
0
,
@domain
.
records
.
where
(
type
:
'CNAME'
)
.
count
,
"0 CNAMEs for
#{
del
}
"
end
}
test
'add errors when a record already exists'
do
create
(
:v4_ptr
,
domain
:
@domain
,
name
:
'194'
)
assert_not
@record
.
save
,
'delegation with records should fail'
assert_not_empty
@record
.
errors
[
:name
]
end
test
'allow second delegation with a different NS'
do
@record
.
save!
assert_no_difference
"@domain.records.where(type: 'CNAME').count"
do
NS
.
create!
(
domain
:
@domain
,
name
:
@record
.
name
,
content
:
'ns-other.example.com'
)
end
end
test
'drop records after all NS are deleted'
do
@record
.
save!
second
=
NS
.
create!
(
domain
:
@domain
,
name
:
@record
.
name
,
content
:
'ns-other.example.com'
)
# CNAMEs are not deleted
assert_no_difference
'@domain.records.where(type: "CNAME").count'
do
second
.
destroy
end
# Deleting the last NS delegation should delete all CNAMEs
@record
.
destroy
assert_equal
0
,
@domain
.
records
.
where
(
type
:
'CNAME'
)
.
count
,
'zero delegations'
end
end
class
ClasslessDelegationWithDash
<
ActiveSupport
::
TestCase
setup
do
@record
=
build
(
:cd_ns
,
name
:
'192-29'
)
@domain
=
@record
.
domain
end
test
'creates delegation'
do
assert
@record
.
save
assert
@record
.
classless_delegation?
octets
=
[
192
,
193
,
194
,
195
,
196
,
197
,
198
,
199
]
assert_equal
octets
.
size
,
@domain
.
records
.
where
(
type
:
'CNAME'
)
.
count
octets
.
each
{
|
octet
|
cname
=
@domain
.
records
.
where
(
type
:
'CNAME'
,
name
:
"
#{
octet
}
.
#{
@domain
.
name
}
"
)
.
first
assert
cname
,
"
#{
octet
}
delegation"
assert_not
cname
.
editable?
,
"
#{
octet
}
editable"
assert
cname
.
classless_delegated?
,
"
#{
octet
}
classless_delegated"
}
end
test
'delete delegation'
do
assert
@record
.
save
@record
.
destroy
assert_equal
0
,
@domain
.
records
.
where
(
type
:
'CNAME'
)
.
count
,
'zero delegations'
end
[
'0-24'
,
# too big
'0-32'
,
# too small
'191-29'
,
'-192-29'
,
'192--29'
,
'192-29-29'
,
'192'
,
].
each
{
|
del
|
test
"invalid delegation
#{
del
}
"
do
@record
.
name
=
del
@record
.
save!
assert_not
@record
.
classless_delegation?
assert_equal
0
,
@domain
.
records
.
where
(
type
:
'CNAME'
)
.
count
,
"0 CNAMEs for
#{
del
}
"
end
}
test
'add errors when a record already exists'
do
create
(
:v4_ptr
,
domain
:
@domain
,
name
:
'194'
)
assert_not
@record
.
save
,
'delegation with records should fail'
assert_not_empty
@record
.
errors
[
:name
]
end
test
'allow second delegation with a different NS'
do
@record
.
save!
assert_no_difference
"@domain.records.where(type: 'CNAME').count"
do
NS
.
create!
(
domain
:
@domain
,
name
:
@record
.
name
,
content
:
'ns-other.example.com'
)
end
end
test
'drop records after all NS are deleted'
do
@record
.
save!
second
=
NS
.
create!
(
domain
:
@domain
,
name
:
@record
.
name
,
content
:
'ns-other.example.com'
)
# CNAMEs are not deleted
assert_no_difference
'@domain.records.where(type: "CNAME").count'
do
second
.
destroy
end
# Deleting the last NS delegation should delete all CNAMEs
@record
.
destroy
assert_equal
0
,
@domain
.
records
.
where
(
type
:
'CNAME'
)
.
count
,
'zero delegations'
end
end
end
Event Timeline
Log In to Comment