From ca8855767d7cfdae795282f173b6e265123cc06d Mon Sep 17 00:00:00 2001 From: Herman Slatman Date: Thu, 11 Jan 2024 11:47:06 +0100 Subject: [PATCH] Fix and add more tests to Wire order identifier validation --- acme/api/order_test.go | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/acme/api/order_test.go b/acme/api/order_test.go index abcd7fc8..8ebf9c60 100644 --- a/acme/api/order_test.go +++ b/acme/api/order_test.go @@ -96,14 +96,34 @@ func TestNewOrderRequest_Validate(t *testing.T) { err: acme.NewError(acme.ErrorMalformedType, "invalid IP address: %s", "192.168.42.1000"), } }, - "fail/bad-identifier/wireapp-prefix-mismatch": func(t *testing.T) test { + "fail/bad-identifier/wireapp-invalid-uri": func(t *testing.T) test { return test{ nor: &NewOrderRequest{ Identifiers: []acme.Identifier{ {Type: "wireapp-id", Value: "{}"}, }, }, - err: acme.NewError(acme.ErrorMalformedType, "invalid client ID, it's supposed to be a valid URI"), + err: acme.NewError(acme.ErrorMalformedType, `invalid Wire client ID "": invalid Wire client ID URI "": error parsing : scheme is missing`), + } + }, + "fail/bad-identifier/wireapp-wrong-scheme": func(t *testing.T) test { + return test{ + nor: &NewOrderRequest{ + Identifiers: []acme.Identifier{ + {Type: "wireapp-id", Value: `{"name": "Smith, Alice M (QA)", "domain": "example.com", "client-id": "nowireapp://example.com", "handle": "wireapp://%40alice.smith.qa@example.com"}`}, + }, + }, + err: acme.NewError(acme.ErrorMalformedType, `invalid Wire client ID "nowireapp://example.com": invalid Wire client ID scheme "nowireapp"; expected "wireapp"`), + } + }, + "fail/bad-identifier/wireapp-invalid-user-parts": func(t *testing.T) test { + return test{ + nor: &NewOrderRequest{ + Identifiers: []acme.Identifier{ + {Type: "wireapp-id", Value: `{"name": "Smith, Alice M (QA)", "domain": "example.com", "client-id": "wireapp://user-device@example.com", "handle": "wireapp://%40alice.smith.qa@example.com"}`}, + }, + }, + err: acme.NewError(acme.ErrorMalformedType, `invalid Wire client ID "wireapp://user-device@example.com": invalid Wire client ID username "user-device"`), } }, "ok": func(t *testing.T) test { @@ -184,7 +204,7 @@ func TestNewOrderRequest_Validate(t *testing.T) { naf: naf, } }, - "ok/wireapp-prefix": func(t *testing.T) test { + "ok/wireapp-idd": func(t *testing.T) test { nbf := time.Now().UTC().Add(time.Minute) naf := time.Now().UTC().Add(5 * time.Minute) return test{