-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
182 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package keycloakb | ||
|
||
import ( | ||
"github.com/cloudtrust/keycloak-bridge/internal/constants" | ||
"github.com/cloudtrust/keycloak-client" | ||
kc "github.com/cloudtrust/keycloak-client" | ||
) | ||
|
||
var ( | ||
// These attributes should not be used anymore | ||
attrbBirthDateLegacy = kc.AttributeKey("birthDate") | ||
attrbGenderLegacy = kc.AttributeKey("gender") | ||
|
||
piiAttributes = map[kc.AttributeKey]kc.AttributeKey{ | ||
constants.AttrbBirthDate: attrbBirthDateLegacy, | ||
constants.AttrbGender: attrbGenderLegacy, | ||
} | ||
) | ||
|
||
// CheckPII verify that PII are located in the well named attributes | ||
func CheckPII(user *keycloak.UserRepresentation) { | ||
for attrbSecure, attrbLegacy := range piiAttributes { | ||
if value := user.GetAttributeString(attrbSecure); value == nil { | ||
if value = user.GetAttributeString(attrbLegacy); value != nil { | ||
user.SetAttributeString(attrbSecure, *value) | ||
delete(*user.Attributes, attrbLegacy) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package keycloakb | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/cloudtrust/keycloak-bridge/internal/constants" | ||
|
||
kc "github.com/cloudtrust/keycloak-client" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCheckPII(t *testing.T) { | ||
var kcUser kc.UserRepresentation | ||
|
||
t.Run("No attributes", func(t *testing.T) { | ||
CheckPII(&kcUser) | ||
assert.Nil(t, kcUser.Attributes) | ||
}) | ||
t.Run("One attribute without PII", func(t *testing.T) { | ||
kcUser.SetAttributeString(kc.AttributeKey("non-pii"), "value") | ||
CheckPII(&kcUser) | ||
assert.Len(t, *kcUser.Attributes, 1) | ||
}) | ||
t.Run("Two PII attributes in un-encrypted version", func(t *testing.T) { | ||
var birthDate = "01.01.1999" | ||
var gender = "M" | ||
kcUser = kc.UserRepresentation{} | ||
kcUser.SetAttributeString(attrbBirthDateLegacy, birthDate) | ||
kcUser.SetAttributeString(attrbGenderLegacy, gender) | ||
CheckPII(&kcUser) | ||
assert.Len(t, *kcUser.Attributes, 2) | ||
assert.Nil(t, kcUser.GetAttributeString(attrbBirthDateLegacy)) | ||
assert.Nil(t, kcUser.GetAttributeString(attrbGenderLegacy)) | ||
assert.Equal(t, birthDate, *kcUser.GetAttributeString(constants.AttrbBirthDate)) | ||
assert.Equal(t, gender, *kcUser.GetAttributeString(constants.AttrbGender)) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.