-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support multiple keypairs per host (#154)
* chore: update gitignore * chore: compute coverage * support for multiple pubkey-pairs per host
- Loading branch information
1 parent
4b7f669
commit edca9a5
Showing
7 changed files
with
256 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ | |
/dyndns-server | ||
/dyndns-client | ||
/.idea | ||
/keypair.json | ||
dist/ |
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,53 @@ | ||
package conf | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestReadServerConfig(t *testing.T) { | ||
type args struct { | ||
path string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want *ServerConf | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "happy path", | ||
args: args{"../contrib/server.json"}, | ||
want: &ServerConf{ | ||
KnownHosts: map[string][]string{ | ||
"host": []string{"key1", "key2"}, | ||
}, | ||
HostedZoneId: "hosted-zone-id-x", | ||
MetricsListener: ":666", | ||
MqttConfig: MqttConfig{ | ||
Brokers: []string{"broker-1", "broker-2"}, | ||
ClientId: "my-client-id", | ||
}, | ||
VaultConfig: VaultConfig{ | ||
RoleName: "my-role-name", | ||
VaultAddr: "https://vault:8200", | ||
AppRoleId: "my-approle-id", | ||
AppRoleSecret: "my-approle-secret", | ||
VaultToken: "the-holy-token", | ||
}, | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := ReadServerConfig(tt.args.path) | ||
if (err != nil) != tt.wantErr { | ||
t.Errorf("ReadServerConfig() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("ReadServerConfig() got = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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,20 @@ | ||
{ | ||
"known_hosts": { | ||
"host": [ | ||
"key1", | ||
"key2" | ||
] | ||
}, | ||
"hosted_zone_id": "hosted-zone-id-x", | ||
"metrics_listen": ":666", | ||
"brokers": [ | ||
"broker-1", | ||
"broker-2" | ||
], | ||
"client_id": "my-client-id", | ||
"vault_role_name": "my-role-name", | ||
"vault_addr": "https://vault:8200", | ||
"vault_app_role_id": "my-approle-id", | ||
"vault_app_role_secret": "my-approle-secret", | ||
"vault_token": "the-holy-token" | ||
} |
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,140 @@ | ||
package server | ||
|
||
import ( | ||
"github.com/soerenschneider/dyndns/internal/common" | ||
"github.com/soerenschneider/dyndns/internal/events" | ||
"github.com/soerenschneider/dyndns/internal/verification" | ||
"github.com/soerenschneider/dyndns/server/dns" | ||
"testing" | ||
"time" | ||
) | ||
|
||
type SimpleVerifier struct { | ||
verificationResult bool | ||
} | ||
|
||
func (s SimpleVerifier) Verify(signature string, ip common.ResolvedIp) bool { | ||
return s.verificationResult | ||
} | ||
|
||
func TestServer_verifyMessage(t *testing.T) { | ||
type fields struct { | ||
knownHosts map[string][]verification.VerificationKey | ||
listener events.EventListener | ||
requests chan common.Envelope | ||
propagator dns.Propagator | ||
cache map[string]common.ResolvedIp | ||
} | ||
type args struct { | ||
env common.Envelope | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
args args | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "happy path", | ||
fields: fields{ | ||
knownHosts: map[string][]verification.VerificationKey{ | ||
"my-host.tld": []verification.VerificationKey{ | ||
&SimpleVerifier{false}, | ||
&SimpleVerifier{true}, | ||
}, | ||
"other-host.tld": []verification.VerificationKey{ | ||
&SimpleVerifier{false}, | ||
&SimpleVerifier{true}, | ||
}, | ||
}, | ||
listener: nil, | ||
requests: nil, | ||
propagator: nil, | ||
cache: map[string]common.ResolvedIp{}, | ||
}, | ||
args: args{ | ||
env: common.Envelope{ | ||
PublicIp: common.ResolvedIp{ | ||
IpV4: "8.8.4.4", | ||
Host: "my-host.tld", | ||
Timestamp: time.Now(), | ||
}, | ||
Signature: "dummy-value", | ||
}, | ||
}, | ||
wantErr: false, | ||
}, | ||
|
||
{ | ||
name: "validation not successful", | ||
fields: fields{ | ||
knownHosts: map[string][]verification.VerificationKey{ | ||
"my-host.tld": []verification.VerificationKey{ | ||
&SimpleVerifier{false}, | ||
}, | ||
"other-host.tld": []verification.VerificationKey{ | ||
&SimpleVerifier{false}, | ||
}, | ||
}, | ||
listener: nil, | ||
requests: nil, | ||
propagator: nil, | ||
cache: map[string]common.ResolvedIp{}, | ||
}, | ||
args: args{ | ||
env: common.Envelope{ | ||
PublicIp: common.ResolvedIp{ | ||
IpV4: "8.8.4.4", | ||
Host: "my-host.tld", | ||
Timestamp: time.Now(), | ||
}, | ||
Signature: "dummy-value", | ||
}, | ||
}, | ||
wantErr: true, | ||
}, | ||
|
||
{ | ||
name: "ho host", | ||
fields: fields{ | ||
knownHosts: map[string][]verification.VerificationKey{ | ||
"my-host.tld": []verification.VerificationKey{ | ||
&SimpleVerifier{false}, | ||
}, | ||
"other-host.tld": []verification.VerificationKey{ | ||
&SimpleVerifier{false}, | ||
}, | ||
}, | ||
listener: nil, | ||
requests: nil, | ||
propagator: nil, | ||
cache: map[string]common.ResolvedIp{}, | ||
}, | ||
args: args{ | ||
env: common.Envelope{ | ||
PublicIp: common.ResolvedIp{ | ||
IpV4: "8.8.4.4", | ||
Host: "not-found.tld", | ||
Timestamp: time.Now(), | ||
}, | ||
Signature: "dummy-value", | ||
}, | ||
}, | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
server := &Server{ | ||
knownHosts: tt.fields.knownHosts, | ||
listener: tt.fields.listener, | ||
requests: tt.fields.requests, | ||
propagator: tt.fields.propagator, | ||
cache: tt.fields.cache, | ||
} | ||
if err := server.verifyMessage(tt.args.env); (err != nil) != tt.wantErr { | ||
t.Errorf("verifyMessage() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
}) | ||
} | ||
} |