Add REST API handler tests for zones, records, and middleware
Cover all REST handlers with httptest-based tests using real SQLite: zones (list, get, create, update, delete), records (list, get, create, update, delete with validation/conflict cases), requireAdmin middleware (admin, non-admin, missing context), and utility functions (writeJSON, writeError, extractBearerToken, tokenInfoFromContext). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,8 +2,9 @@ syntax = "proto3";
|
||||
|
||||
package mcns.v1;
|
||||
|
||||
option go_package = "git.wntrmute.dev/kyle/mcns/gen/mcns/v1";
|
||||
option go_package = "git.wntrmute.dev/kyle/mcns/gen/mcns/v1;mcnsv1";
|
||||
|
||||
// AdminService exposes server health and administrative operations.
|
||||
service AdminService {
|
||||
rpc Health(HealthRequest) returns (HealthResponse);
|
||||
}
|
||||
|
||||
@@ -2,8 +2,9 @@ syntax = "proto3";
|
||||
|
||||
package mcns.v1;
|
||||
|
||||
option go_package = "git.wntrmute.dev/kyle/mcns/gen/mcns/v1";
|
||||
option go_package = "git.wntrmute.dev/kyle/mcns/gen/mcns/v1;mcnsv1";
|
||||
|
||||
// AuthService handles authentication by delegating to MCIAS.
|
||||
service AuthService {
|
||||
rpc Login(LoginRequest) returns (LoginResponse);
|
||||
rpc Logout(LogoutRequest) returns (LogoutResponse);
|
||||
@@ -12,6 +13,7 @@ service AuthService {
|
||||
message LoginRequest {
|
||||
string username = 1;
|
||||
string password = 2;
|
||||
// TOTP code for two-factor authentication, if enabled on the account.
|
||||
string totp_code = 3;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,10 +2,11 @@ syntax = "proto3";
|
||||
|
||||
package mcns.v1;
|
||||
|
||||
option go_package = "git.wntrmute.dev/kyle/mcns/gen/mcns/v1";
|
||||
option go_package = "git.wntrmute.dev/kyle/mcns/gen/mcns/v1;mcnsv1";
|
||||
|
||||
import "google/protobuf/timestamp.proto";
|
||||
|
||||
// RecordService manages DNS records within zones.
|
||||
service RecordService {
|
||||
rpc ListRecords(ListRecordsRequest) returns (ListRecordsResponse);
|
||||
rpc CreateRecord(CreateRecordRequest) returns (Record);
|
||||
@@ -16,8 +17,10 @@ service RecordService {
|
||||
|
||||
message Record {
|
||||
int64 id = 1;
|
||||
// Zone name this record belongs to (e.g. "example.com.").
|
||||
string zone = 2;
|
||||
string name = 3;
|
||||
// DNS record type (A, AAAA, CNAME, MX, TXT, etc.).
|
||||
string type = 4;
|
||||
string value = 5;
|
||||
int32 ttl = 6;
|
||||
@@ -27,7 +30,9 @@ message Record {
|
||||
|
||||
message ListRecordsRequest {
|
||||
string zone = 1;
|
||||
// Optional filter by record name.
|
||||
string name = 2;
|
||||
// Optional filter by record type (A, AAAA, CNAME, etc.).
|
||||
string type = 3;
|
||||
}
|
||||
|
||||
@@ -36,6 +41,7 @@ message ListRecordsResponse {
|
||||
}
|
||||
|
||||
message CreateRecordRequest {
|
||||
// Zone name the record will be created in; must reference an existing zone.
|
||||
string zone = 1;
|
||||
string name = 2;
|
||||
string type = 3;
|
||||
|
||||
@@ -2,10 +2,11 @@ syntax = "proto3";
|
||||
|
||||
package mcns.v1;
|
||||
|
||||
option go_package = "git.wntrmute.dev/kyle/mcns/gen/mcns/v1";
|
||||
option go_package = "git.wntrmute.dev/kyle/mcns/gen/mcns/v1;mcnsv1";
|
||||
|
||||
import "google/protobuf/timestamp.proto";
|
||||
|
||||
// ZoneService manages DNS zones and their SOA parameters.
|
||||
service ZoneService {
|
||||
rpc ListZones(ListZonesRequest) returns (ListZonesResponse);
|
||||
rpc CreateZone(CreateZoneRequest) returns (Zone);
|
||||
|
||||
Reference in New Issue
Block a user