feat: change the separator between user-id & device-id in a client-id. Use '!' instead of ':'

This commit is contained in:
beltram 2024-01-05 09:56:34 +01:00 committed by Herman Slatman
parent 90b5347887
commit 84e9682476
No known key found for this signature in database
GPG Key ID: F4D8A44EA0A75A4F
3 changed files with 13 additions and 7 deletions

View File

@ -199,7 +199,7 @@ func TestIMIntegration(t *testing.T) {
Identifiers: []acme.Identifier{ Identifiers: []acme.Identifier{
{ {
Type: "wireapp-id", Type: "wireapp-id",
Value: `{"name": "Smith, Alice M (QA)", "domain": "example.com", "client-id": "wireapp://lJGYPz0ZRq2kvc_XpdaDlA:ed416ce8ecdd9fad@example.com", "handle": "wireapp://%40alice.smith.qa@example.com"}`, Value: `{"name": "Smith, Alice M (QA)", "domain": "example.com", "client-id": "wireapp://lJGYPz0ZRq2kvc_XpdaDlA!ed416ce8ecdd9fad@example.com", "handle": "wireapp://%40alice.smith.qa@example.com"}`,
}, },
}, },
} }
@ -377,7 +377,7 @@ func TestIMIntegration(t *testing.T) {
}, },
}) })
qUserID, err := url.Parse("wireapp://lJGYPz0ZRq2kvc_XpdaDlA:ed416ce8ecdd9fad@example.com") qUserID, err := url.Parse("wireapp://lJGYPz0ZRq2kvc_XpdaDlA!ed416ce8ecdd9fad@example.com")
if err != nil { if err != nil {
t.Fatal("parse user ID URI", err) t.Fatal("parse user ID URI", err)
} }

View File

@ -190,7 +190,7 @@ func TestNewOrderRequest_Validate(t *testing.T) {
return test{ return test{
nor: &NewOrderRequest{ nor: &NewOrderRequest{
Identifiers: []acme.Identifier{ Identifiers: []acme.Identifier{
{Type: "wireapp-id", Value: `{"name": "Smith, Alice M (QA)", "domain": "example.com", "client-id": "wireapp://lJGYPz0ZRq2kvc_XpdaDlA:ed416ce8ecdd9fad@example.com", "handle": "wireapp://%40alice.smith.qa@example.com"}`}, {Type: "wireapp-id", Value: `{"name": "Smith, Alice M (QA)", "domain": "example.com", "client-id": "wireapp://lJGYPz0ZRq2kvc_XpdaDlA!ed416ce8ecdd9fad@example.com", "handle": "wireapp://%40alice.smith.qa@example.com"}`},
}, },
NotAfter: naf, NotAfter: naf,
NotBefore: nbf, NotBefore: nbf,

View File

@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"go.step.sm/crypto/kms/uri" "go.step.sm/crypto/kms/uri"
"strings"
) )
type WireIDJSON struct { type WireIDJSON struct {
@ -24,16 +25,21 @@ type ClientID struct {
Domain string Domain string
} }
// ClientId format is : "wireapp://CzbfFjDOQrenCbDxVmgnFw!594930e9d50bb175@wire.com" where '!' is used as a separator
// between the user id & device id
func ParseClientID(clientID string) (ClientID, error) { func ParseClientID(clientID string) (ClientID, error) {
clientIdUri, err := uri.Parse(clientID) clientIdUri, err := uri.Parse(clientID)
if err != nil { if err != nil {
return ClientID{}, fmt.Errorf("invalid client id URI") return ClientID{}, fmt.Errorf("invalid client id URI")
} }
username := clientIdUri.User.Username() fullUsername := clientIdUri.User.Username()
deviceId, _ := clientIdUri.User.Password() parts := strings.SplitN(fullUsername, "!", 2)
if len(parts) != 2 {
return ClientID{}, fmt.Errorf("invalid client id")
}
return ClientID{ return ClientID{
Username: username, Username: parts[0],
DeviceID: deviceId, DeviceID: parts[1],
Domain: clientIdUri.Host, Domain: clientIdUri.Host,
}, nil }, nil
} }