DImuthuUpe commented on code in PR #566:
URL: https://github.com/apache/airavata-custos/pull/566#discussion_r3954322043


##########
connectors/COmanage/Identity-Provisioner/internal/operations/compose_test.go:
##########
@@ -148,3 +149,126 @@ func TestBuildCreatePersonBody_Shape(t *testing.T) {
                t.Errorf("no Identifier block expected without a sub: %s", raw)
        }
 }
+
+// The composite PUT deletes anything the body leaves out, so merging an
+// identifier must return the person whole.
+func TestMergeIdentifier_KeepsEveryPropertyOfThePerson(t *testing.T) {
+       person := `{
+      "CoPerson": {"meta": {"id": 244}, "co_id": 2, "status": "A", 
"date_of_birth": null, "timezone": null},
+      "Name": [{"given": "Test", "family": "Person", "type": "official", 
"primary_name": true, "language": "en"}],
+      "EmailAddress": [{"mail": "[email protected]", "type": "official", 
"verified": true}],
+      "Identifier": [
+        {"identifier": "Person100099", "type": "comanage_id", "login": false, 
"status": "A"},
+        {"identifier": "2000093", "type": "uidnumber", "login": false, 
"status": "A"},
+        {"identifier": "2000093", "type": "gidnumber", "login": false, 
"status": "A"},
+        {"identifier": "custos-tperson", "type": "uid", "login": false, 
"status": "A"}
+      ],
+      "CoPersonRole": [{"affiliation": "member", "status": "A"}],
+      "CoGroupMember": [{"co_group_id": 64, "member": true, "owner": false}],
+      "UnixClusterAccount": [{"username": "custos-tperson", "uid": 2000093, 
"unix_cluster_id": 1}],
+      "Url": [],
+      "SshKey": []
+    }`
+
+       merged, err := mergeIdentifier(json.RawMessage(person), "oidcsub", 
"http://idp.invalid/users/9";, true)
+       if err != nil {
+               t.Fatalf("mergeIdentifier: %v", err)
+       }
+
+       var before, after map[string]json.RawMessage
+       if err := json.Unmarshal([]byte(person), &before); err != nil {
+               t.Fatalf("decode fixture: %v", err)
+       }
+       if err := json.Unmarshal(merged, &after); err != nil {
+               t.Fatalf("decode merged: %v", err)
+       }
+
+       // Every section survives, and only Identifier is allowed to differ.
+       for key, want := range before {
+               got, ok := after[key]
+               if !ok {
+                       t.Fatalf("PUT body dropped %q, the registry would 
delete it", key)
+               }
+               if key == "Identifier" {
+                       continue
+               }
+               if !sameJSON(t, got, want) {
+                       t.Errorf("%s changed\n got: %s\nwant: %s", key, got, 
want)
+               }
+       }
+       for key := range after {
+               if _, ok := before[key]; !ok {
+                       t.Errorf("PUT body invented %q", key)
+               }
+       }
+
+       // Every identifier the person already had is still there, plus the new 
one.
+       var idents []struct {
+               Identifier string `json:"identifier"`
+               Type       string `json:"type"`
+               Login      bool   `json:"login"`
+               Status     string `json:"status"`
+       }
+       if err := json.Unmarshal(after["Identifier"], &idents); err != nil {
+               t.Fatalf("decode identifiers: %v", err)
+       }
+       found := map[string]string{}
+       for _, id := range idents {
+               found[id.Type] = id.Identifier
+               if id.Status != "A" {
+                       t.Errorf("%s lost its status: %+v", id.Type, id)
+               }
+       }
+       for typ, want := range map[string]string{
+               "comanage_id": "Person100099",
+               "uidnumber":   "2000093",
+               "gidnumber":   "2000093",
+               "uid":         "custos-tperson",
+               "oidcsub":     "http://idp.invalid/users/9";,
+       } {
+               if found[typ] != want {
+                       t.Errorf("identifier %s = %q, want %q", typ, 
found[typ], want)
+               }
+       }
+       if len(idents) != 5 {
+               t.Errorf("identifier count = %d, want 5", len(idents))
+       }
+}
+
+// A person whose sub changes must end with one oidcsub, not two.
+func TestMergeIdentifier_ReplacesSameType(t *testing.T) {

Review Comment:
   Are these tests intentionally written?



##########
connectors/COmanage/Identity-Provisioner/internal/operations/ensure_cluster_admin_test.go:
##########
@@ -0,0 +1,201 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package operations
+
+import (
+       "context"
+       "encoding/json"
+       "io"
+       "net/http"
+       "net/http/httptest"
+       "strings"
+       "testing"
+       "time"
+
+       
"github.com/apache/airavata-custos/connectors/COmanage/Identity-Provisioner/internal/client"
+       "github.com/apache/airavata-custos/pkg/models"
+)
+
+const adminGroupName = "cluster-admins"
+
+// adminGroupServer serves the person composite and the admin group lookup.
+// existingMember decides whether the person is already in the group, and every
+// POSTed membership body is appended to posted.
+func adminGroupServer(t *testing.T, groupFound, existingMember bool, posted 
*[]client.CoGroupMemberCreateOne) *httptest.Server {

Review Comment:
   Not sure I follow this test case



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to