-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from johanix/music-unit-testtest
Music unit testtest
- Loading branch information
Showing
11 changed files
with
872 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
// join_sync_dnskeys_test.go (written by CodeRabbit) | ||
|
||
package fsm | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/johanix/tdns/music" | ||
"github.com/johanix/tdns/music/mocks" | ||
"github.com/miekg/dns" | ||
) | ||
|
||
func TestJoinSyncDnskeys(t *testing.T) { | ||
// Set up a mock zone and signers | ||
zone := &music.Zone{ | ||
Name: "example.com", | ||
ZoneType: "normal", | ||
SGroup: &music.SignerGroup{ | ||
Name: "default", | ||
SignerMap: map[string]*music.Signer{ | ||
"signer1": { | ||
Name: "signer1", | ||
Method: "mock", | ||
}, | ||
"signer2": { | ||
Name: "signer2", | ||
Method: "mock", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
// Mock DNSKEY records for each signer | ||
dnskey1 := &dns.DNSKEY{ | ||
Hdr: dns.RR_Header{ | ||
Name: "example.com.", | ||
Rrtype: dns.TypeDNSKEY, | ||
Class: dns.ClassINET, | ||
Ttl: 3600, | ||
}, | ||
Flags: 256, // ZSK | ||
Protocol: 3, | ||
Algorithm: dns.RSASHA256, | ||
PublicKey: "publickey1", | ||
} | ||
|
||
dnskey2 := &dns.DNSKEY{ | ||
Hdr: dns.RR_Header{ | ||
Name: "example.com.", | ||
Rrtype: dns.TypeDNSKEY, | ||
Class: dns.ClassINET, | ||
Ttl: 3600, | ||
}, | ||
Flags: 256, // ZSK | ||
Protocol: 3, | ||
Algorithm: dns.RSASHA256, | ||
PublicKey: "publickey2", | ||
} | ||
|
||
// Set up mock updater | ||
music.Updaters["mock"] = &mocks.MockUpdater{ | ||
FetchRRset: func(signer *music.Signer, zoneName, owner string, rrtype uint16) (error, []dns.RR) { | ||
if signer.Name == "signer1" { | ||
return nil, []dns.RR{dnskey1} | ||
} | ||
if signer.Name == "signer2" { | ||
return nil, []dns.RR{dnskey2} | ||
} | ||
return nil, nil | ||
}, | ||
Update: func(signer *music.Signer, zoneName, owner string, inserts, removes *[][]dns.RR) error { | ||
// Simulate successful update | ||
return nil | ||
}, | ||
} | ||
|
||
// Execute the function under test | ||
success := JoinSyncDnskeys(zone) | ||
if !success { | ||
t.Errorf("JoinSyncDnskeys failed") | ||
} | ||
|
||
// Verify that keys have been set for signers | ||
if len(zone.SignerDnskeys) == 0 { | ||
t.Errorf("SignerDnskeys map is empty") | ||
} | ||
} | ||
|
||
func TestVerifyDnskeysSynched(t *testing.T) { | ||
// Set up mock zone and signers | ||
zone := &music.Zone{ | ||
Name: "example.com", | ||
ZoneType: "normal", | ||
SGroup: &music.SignerGroup{ | ||
Name: "default", | ||
SignerMap: map[string]*music.Signer{ | ||
"signer1": { | ||
Name: "signer1", | ||
Method: "mock", | ||
}, | ||
"signer2": { | ||
Name: "signer2", | ||
Method: "mock", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
dnskey := &dns.DNSKEY{ | ||
Hdr: dns.RR_Header{ | ||
Name: "example.com.", | ||
Rrtype: dns.TypeDNSKEY, | ||
Class: dns.ClassINET, | ||
Ttl: 3600, | ||
}, | ||
Flags: 256, | ||
Protocol: 3, | ||
Algorithm: dns.RSASHA256, | ||
PublicKey: "publickey", | ||
} | ||
|
||
// Both signers have the same DNSKEY | ||
music.Updaters["mock"] = &mocks.MockUpdater{ | ||
FetchRRsetFunc: func(signer *music.Signer, zoneName, owner string, rrtype uint16) (error, []dns.RR) { | ||
return nil, []dns.RR{dnskey} | ||
}, | ||
} | ||
|
||
// Execute the function under test | ||
success := VerifyDnskeysSynched(zone) | ||
if !success { | ||
t.Errorf("VerifyDnskeysSynched failed: DNSKEYs are not synchronized") | ||
} | ||
} | ||
|
||
func TestVerifyDnskeysNotSynched(t *testing.T) { | ||
// Set up mock zone and signers with different DNSKEYs | ||
zone := &music.Zone{ | ||
Name: "example.com", | ||
ZoneType: "normal", | ||
SGroup: &music.SignerGroup{ | ||
Name: "default", | ||
SignerMap: map[string]*music.Signer{ | ||
"signer1": { | ||
Name: "signer1", | ||
Method: "mock", | ||
}, | ||
"signer2": { | ||
Name: "signer2", | ||
Method: "mock", | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
dnskey1 := &dns.DNSKEY{ | ||
Hdr: dns.RR_Header{ | ||
Name: "example.com.", | ||
Rrtype: dns.TypeDNSKEY, | ||
Class: dns.ClassINET, | ||
Ttl: 3600, | ||
}, | ||
Flags: 256, | ||
Protocol: 3, | ||
Algorithm: dns.RSASHA256, | ||
PublicKey: "publickey1", | ||
} | ||
|
||
dnskey2 := &dns.DNSKEY{ | ||
Hdr: dns.RR_Header{ | ||
Name: "example.com.", | ||
Rrtype: dns.TypeDNSKEY, | ||
Class: dns.ClassINET, | ||
Ttl: 3600, | ||
}, | ||
Flags: 256, | ||
Protocol: 3, | ||
Algorithm: dns.RSASHA256, | ||
PublicKey: "publickey2", | ||
} | ||
|
||
// Signers have different DNSKEYs | ||
music.Updaters["mock"] = &mocks.MockUpdater{ | ||
FetchRRsetFunc: func(signer *music.Signer, zoneName, owner string, rrtype uint16) (error, []dns.RR) { | ||
if signer.Name == "signer1" { | ||
return nil, []dns.RR{dnskey1} | ||
} | ||
if signer.Name == "signer2" { | ||
return nil, []dns.RR{dnskey2} | ||
} | ||
return nil, nil | ||
}, | ||
} | ||
|
||
// Execute the function under test | ||
success := VerifyDnskeysSynched(zone) | ||
if success { | ||
t.Errorf("VerifyDnskeysSynched should have failed: DNSKEYs are not synchronized") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
module mocks | ||
|
||
go 1.23.2 | ||
|
||
replace ( | ||
github.com/johanix/tdns/music => ../ | ||
github.com/johanix/tdns/music/fsm => ../fsm | ||
github.com/johanix/tdns/tdns => ../../tdns | ||
) | ||
|
||
require ( | ||
github.com/johanix/tdns/music v0.0.0-00010101000000-000000000000 | ||
github.com/miekg/dns v1.1.62 | ||
github.com/stretchr/testify v1.9.0 | ||
) | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/fsnotify/fsnotify v1.6.0 // indirect | ||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect | ||
github.com/go-playground/locales v0.14.1 // indirect | ||
github.com/go-playground/universal-translator v0.18.1 // indirect | ||
github.com/go-playground/validator/v10 v10.22.1 // indirect | ||
github.com/gookit/color v1.5.4 // indirect | ||
github.com/gookit/goutil v0.6.15 // indirect | ||
github.com/gorilla/mux v1.8.1 // indirect | ||
github.com/hashicorp/hcl v1.0.0 // indirect | ||
github.com/johanix/tdns/tdns v0.0.0-00010101000000-000000000000 // indirect | ||
github.com/leodido/go-urn v1.4.0 // indirect | ||
github.com/magiconair/properties v1.8.6 // indirect | ||
github.com/mattn/go-sqlite3 v1.14.16 // indirect | ||
github.com/mitchellh/mapstructure v1.5.0 // indirect | ||
github.com/orcaman/concurrent-map/v2 v2.0.1 // indirect | ||
github.com/pelletier/go-toml v1.9.5 // indirect | ||
github.com/pelletier/go-toml/v2 v2.0.5 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/spf13/afero v1.9.2 // indirect | ||
github.com/spf13/cast v1.5.0 // indirect | ||
github.com/spf13/jwalterweatherman v1.1.0 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
github.com/spf13/viper v1.14.0 // indirect | ||
github.com/stretchr/objx v0.5.2 // indirect | ||
github.com/subosito/gotenv v1.4.1 // indirect | ||
github.com/twotwotwo/sorts v0.0.0-20160814051341-bf5c1f2b8553 // indirect | ||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect | ||
golang.org/x/crypto v0.27.0 // indirect | ||
golang.org/x/exp v0.0.0-20220909182711-5c715a9e8561 // indirect | ||
golang.org/x/mod v0.21.0 // indirect | ||
golang.org/x/net v0.29.0 // indirect | ||
golang.org/x/sync v0.8.0 // indirect | ||
golang.org/x/sys v0.25.0 // indirect | ||
golang.org/x/text v0.18.0 // indirect | ||
golang.org/x/tools v0.25.0 // indirect | ||
gopkg.in/ini.v1 v1.67.0 // indirect | ||
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) |
Oops, something went wrong.