Less verbose tests

This commit is contained in:
Miek Gieben 2011-01-17 20:29:40 +01:00
parent 48cbf55a23
commit 96a55dee9b
6 changed files with 145 additions and 165 deletions

View File

@ -3,8 +3,6 @@ package dns
import (
"testing"
"strings"
"fmt"
"os"
)
func TestSecure(t *testing.T) {
@ -39,13 +37,10 @@ func TestSecure(t *testing.T) {
key.Algorithm = AlgRSASHA256
key.PubKey = "AwEAAcNEU67LJI5GEgF9QLNqLO1SMq1EdoQ6E9f85ha0k0ewQGCblyW2836GiVsm6k8Kr5ECIoMJ6fZWf3CQSQ9ycWfTyOHfmI3eQ/1Covhb2y4bAmL/07PhrL7ozWBW3wBfM335Ft9xjtXHPy7ztCbV9qZ4TVDTW/Iyg0PiwgoXVesz"
fmt.Fprintf(os.Stderr, "%v\n%v\n", sig, soa)
// It should validate. Period is checked seperately, so this will keep on working
if ! sig.Verify(key, []RR{soa}) {
t.Log("Failure to validate")
t.Fail()
} else {
println("It validates!!")
}
}
@ -100,7 +95,6 @@ func TestSignVerify(t *testing.T) {
key.Protocol = 3
key.Algorithm = AlgRSASHA256
privkey, _ := key.Generate(512)
fmt.Fprintf(os.Stderr, "Key tag: %d\n", key.KeyTag())
// Fill in the values of the Sig, before signing
sig := new(RR_RRSIG)
@ -122,8 +116,6 @@ func TestSignVerify(t *testing.T) {
if !sig.Verify(key, []RR{soa}) {
t.Log("Failure to validate")
t.Fail()
} else {
println("It validates!!")
}
}
@ -156,7 +148,6 @@ func TestDnskey(t *testing.T) {
key.Protocol = 3
key.Algorithm = AlgRSASHA256
key.PubKey = "AwEAAcELcuxHosJX3LjbR6EFzsqI3mKivwvO6Y5Kzt/OXYmLQUI8tnOrX9ilT/0qGraxoONayVX3A6bl1pG3h/xOxVEGcJGqbrZnhr2+4S9tW2GWQwevV+NhinE7v6MCCCheVCnAPh0KFb/u14ng3DQizP1spBU/NoAN31l678snBpZX"
fmt.Printf("%v\n", key)
soa := new(RR_SOA)
soa.Hdr = RR_Header{"Miek.nl.", TypeSOA, ClassINET, 875, 0}
@ -244,11 +235,7 @@ func TestKeyGenRSA(t *testing.T) {
sig.SignerName = "miek.nl."
sig.Sign(priv, []RR{soa})
s := key.PrivateKeyString(priv)
fmt.Printf("%s\n", s)
fmt.Printf("%v\n", sig)
//s := key.PrivateKeyString(priv)
}
func TestKeyToDS(t *testing.T) {

View File

@ -1,9 +1,12 @@
package dns
import ( "testing"; "fmt"; "crypto/rsa")
import (
"testing"
"crypto/rsa"
)
func TestConversion(t *testing.T) {
/*
/*
println(StringToSeconds("6w8d50"))
println(StringToSeconds("50"))
println(StringToSeconds("1m1m"))
@ -11,8 +14,8 @@ func TestConversion(t *testing.T) {
println(StringToSeconds("1d"))
println(StringToSeconds("2d"))
println(StringToSeconds("1d1d"))
*/
/*
*/
/*
println(SecondsToString(604800)) // 1w
println(SecondsToString(604799)) // 1w-1
println(SecondsToString(86400)) // 1d
@ -25,7 +28,7 @@ func TestConversion(t *testing.T) {
}
func TestPrivateKeyRead1(t *testing.T) {
a:=`Private-key-format: v1.3
a := `Private-key-format: v1.3
Algorithm: 5 (RSASHA1)
Modulus: vyVjCzz87g3rg9vDj1NJ1tlFP7lEY2pEQLkWGXAFuZM6Fw/bNmEH/z3ybDfsJqx4QQ6YZXN8V2kbzY7oX+tExf6AMiMIcKYzEGwg5xBYFh33du4G+6kE/VzG906ubpaIEnrZOMTdGqE7OwptAqrqXe4uGXY99ZqNdqutOKQyIzs=
PublicExponent: AQAB
@ -40,21 +43,19 @@ Publish: 20101221142359
Activate: 20101221142359`
k := new(RR_DNSKEY)
p,_ := k.PrivateKeySetString(a)
p, _ := k.PrivateKeySetString(a)
p = p
fmt.Printf("%v\n", k)
}
func TestPrivateKeyRead2(t *testing.T) {
b:=`; This is a zone-signing key, keyid 41946, for miek.nl.
; Created: 20110109154937 (Sun Jan 9 16:49:37 2011)
; Publish: 20110109154937 (Sun Jan 9 16:49:37 2011)
; Activate: 20110109154937 (Sun Jan 9 16:49:37 2011)
miek.nl. IN DNSKEY 256 3 5 AwEAAeETsGZdYlTsHK8wc1yo9Zcj4dMEpPWRTYuTmGD3e4Qsk4/uyKf5jhsNZhp8no7GKHTEe7+K1prC4iXo3X5oQyDDmx76hDo5u6fblu/XaQw16wqMDQDPiURUKkzobJlmY6fYNKRz7A01J73V6qDMCvlk+8p+fb0a+LiJ2NJDACln`
/* b:=`; This is a zone-signing key, keyid 41946, for miek.nl.
; Created: 20110109154937 (Sun Jan 9 16:49:37 2011)
; Publish: 20110109154937 (Sun Jan 9 16:49:37 2011)
; Activate: 20110109154937 (Sun Jan 9 16:49:37 2011)
miek.nl. IN DNSKEY 256 3 5 AwEAAeETsGZdYlTsHK8wc1yo9Zcj4dMEpPWRTYuTmGD3e4Qsk4/uyKf5jhsNZhp8no7GKHTEe7+K1prC4iXo3X5oQyDDmx76hDo5u6fblu/XaQw16wqMDQDPiURUKkzobJlmY6fYNKRz7A01J73V6qDMCvlk+8p+fb0a+LiJ2NJDACln`
*/
b = b
a:=`Private-key-format: v1.3
a := `Private-key-format: v1.3
Algorithm: 5 (RSASHA1)
Modulus: 4ROwZl1iVOwcrzBzXKj1lyPh0wSk9ZFNi5OYYPd7hCyTj+7Ip/mOGw1mGnyejsYodMR7v4rWmsLiJejdfmhDIMObHvqEOjm7p9uW79dpDDXrCowNAM+JRFQqTOhsmWZjp9g0pHPsDTUnvdXqoMwK+WT7yn59vRr4uInY0kMAKWc=
PublicExponent: AQAB
@ -83,8 +84,8 @@ Activate: 20110109154937`
}
}
if k.KeyTag() != 41946 {
t.Logf("%v\n", k)
t.Log("Keytag should be 41946")
t.Fail()
}
fmt.Printf("%v\n", k)
}

View File

@ -2,7 +2,6 @@ package resolver
import (
"testing"
"fmt"
"dns"
)
@ -36,8 +35,6 @@ func TestResolver(t *testing.T) {
t.Log("Failed to get an valid answer")
t.Fail()
t.Logf("%v\n", in)
} else {
fmt.Printf("%v\n", in.Dns)
}
ch <- Msg{nil, nil}
@ -76,12 +73,10 @@ func TestResolverEdns(t *testing.T) {
in := <-ch
if in.Dns != nil {
if in.Dns.Rcode != dns.RcodeSuccess {
t.Logf("%v\n", in.Dns)
t.Log("Failed to get an valid answer")
t.Fail()
}
fmt.Printf("%v\n", in.Dns)
} else {
fmt.Printf("Failed to get a good anwer")
}
ch <- Msg{nil, nil}
<-ch // wait for ch to close channel
@ -117,12 +112,10 @@ func TestResolverTsig(t *testing.T) {
in := <-ch
if in.Dns != nil {
if in.Dns.Rcode != dns.RcodeSuccess {
t.Logf("%v\n", in.Dns)
t.Log("Failed to get an valid answer")
t.Fail()
}
fmt.Printf("%v\n", in.Dns)
} else {
fmt.Printf("Failed to get a good anwer")
}
ch <- Msg{nil, nil}
<-ch // wait for ch to close channel
@ -161,6 +154,5 @@ func TestFromFile(t *testing.T) {
t.Log("Failed to get an valid answer")
t.Fail()
}
fmt.Printf("%v\n", in.Dns)
}
}