소스 검색

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

beltram 2 년 전
부모
커밋
84e9682476
3개의 변경된 파일과 13개의 추가작업 그리고 7개의 파일을 삭제
  1. 2 2
      acme/api/im_integration_test.go
  2. 1 1
      acme/api/order_test.go
  3. 10 4
      wire/id.go

+ 2 - 2
acme/api/im_integration_test.go

@@ -199,7 +199,7 @@ func TestIMIntegration(t *testing.T) {
 			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"}`,
+					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 {
 			t.Fatal("parse user ID URI", err)
 		}

+ 1 - 1
acme/api/order_test.go

@@ -190,7 +190,7 @@ func TestNewOrderRequest_Validate(t *testing.T) {
 			return test{
 				nor: &NewOrderRequest{
 					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,
 					NotBefore: nbf,

+ 10 - 4
wire/id.go

@@ -4,6 +4,7 @@ import (
 	"encoding/json"
 	"fmt"
 	"go.step.sm/crypto/kms/uri"
+	"strings"
 )
 
 type WireIDJSON struct {
@@ -24,16 +25,21 @@ type ClientID struct {
 	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) {
 	clientIdUri, err := uri.Parse(clientID)
 	if err != nil {
 		return ClientID{}, fmt.Errorf("invalid client id URI")
 	}
-	username := clientIdUri.User.Username()
-	deviceId, _ := clientIdUri.User.Password()
+	fullUsername := clientIdUri.User.Username()
+	parts := strings.SplitN(fullUsername, "!", 2)
+	if len(parts) != 2 {
+		return ClientID{}, fmt.Errorf("invalid client id")
+	}
 	return ClientID{
-		Username: username,
-		DeviceID: deviceId,
+		Username: parts[0],
+		DeviceID: parts[1],
 		Domain:   clientIdUri.Host,
 	}, nil
 }