Skip to content

Commit

Permalink
Merge pull request #272 from okta/prepare_2_9_2
Browse files Browse the repository at this point in the history
Release v2.9.2
  • Loading branch information
monde authored Nov 30, 2021
2 parents 8b91031 + a49bc87 commit 8d335ca
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 10 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Changelog
Running changelog of releases since `2.0.0-rc.4`

## v2.9.2

### Updates
- Adjustments were made the attributes on the `DeviceAccessPolicyRuleCondition` type.
- Adding `GroupProfileMap` attribute to `GroupProfile` struct to support additional properties. See #268


## v2.9.1

### New Types / Models
Expand Down
8 changes: 6 additions & 2 deletions okta/deviceAccessPolicyRuleCondition.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions okta/groupProfile.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion okta/okta.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion openapi/generator/createdFiles.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions openapi/generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ function getImports(object) {
imports.splice(imports.indexOf("fmt"), 1);
}

if (object.model.modelName === "GroupProfile") {
imports.push("encoding/json");
}

return imports;
}

Expand Down
46 changes: 46 additions & 0 deletions openapi/generator/templates/model.go.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ type {{model.modelName}}Resource resource
)}}
type {{model.modelName}}Resource resource

{{/if}}
{{#if (eq model.modelName "GroupProfile")}}
type {{model.modelName}}Map map[string]interface{}

{{/if}}
{{#if (eq model.modelName "ApplicationSettingsApplication")}}
type {{model.modelName}} map[string]interface{}
Expand All @@ -44,6 +48,9 @@ type {{model.modelName}} string
{{else}}
type {{model.modelName}} struct {
{{{buildModelProperties model}}}
{{#if (eq model.modelName "GroupProfile")}}
{{model.modelName}}Map
{{/if}}
}
{{/if}}
{{#if model.enum}}
Expand Down Expand Up @@ -72,3 +79,42 @@ func (a *{{model.modelName}}) Is{{model.tags.[0]}}Instance() bool {
{{> model.defaultMethod operation=operation alias=alias modelName=../model.modelName}}
{{/each}}
{{/if}}

{{#if (eq model.modelName "GroupProfile")}}
func (a *{{model.modelName}}) UnmarshalJSON(data []byte) error {
if string(data) == "null" || string(data) == `""` {
return nil
}
var profile map[string]interface{}
err := json.Unmarshal(data, &profile)
if err != nil {
return err
}
a.Name, _ = profile["name"].(string)
a.Description, _ = profile["description"].(string)
delete(profile, "name")
delete(profile, "description")
a.{{model.modelName}}Map = profile
return nil
}

func (a {{model.modelName}}) MarshalJSON() ([]byte, error) {
if len(a.{{model.modelName}}Map) == 0 {
return json.Marshal(&struct {
Name string `json:"name"`
Description string `json:"description"`
}{
Name: a.Name,
Description: a.Description,
})
}
if a.Name != "" {
a.{{model.modelName}}Map["name"] = a.Name
}
if a.Description != "" {
a.{{model.modelName}}Map["description"] = a.Description
}
return json.Marshal(a.{{model.modelName}}Map)
}

{{/if}}
40 changes: 34 additions & 6 deletions tests/integration/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package integration

import (
"context"
"encoding/json"
"net/http"
"testing"
"time"
Expand All @@ -29,7 +30,7 @@ import (
"github.com/stretchr/testify/require"
)

func Test_can_get_a_group(t *testing.T) {
func TestCanGetAGroup(t *testing.T) {
ctx, client, err := tests.NewClient(context.TODO())
require.NoError(t, err)
// Create a new group → POST /api/v1/groups
Expand Down Expand Up @@ -59,7 +60,7 @@ func Test_can_get_a_group(t *testing.T) {
"Should have resulted in a 404 when finding a deleted group")
}

func Test_can_list_groups(t *testing.T) {
func TestCanListGroups(t *testing.T) {
ctx, client, err := tests.NewClient(context.TODO())
require.NoError(t, err)
// Create a new group → POST /api/v1/groups
Expand Down Expand Up @@ -89,7 +90,7 @@ func Test_can_list_groups(t *testing.T) {
require.NoError(t, err, "Should not error when deleting a group")
}

func Test_can_search_for_a_group(t *testing.T) {
func TestCanSearchForAGroup(t *testing.T) {
ctx, client, err := tests.NewClient(context.TODO())
require.NoError(t, err)
// Create a new group → POST /api/v1/groups
Expand Down Expand Up @@ -121,7 +122,7 @@ func Test_can_search_for_a_group(t *testing.T) {
require.NoError(t, err, "Should not error when deleting a group")
}

func Test_can_update_a_group(t *testing.T) {
func TestCanUpdateAGroup(t *testing.T) {
ctx, client, err := tests.NewClient(context.TODO())
require.NoError(t, err)
// Create a new group → POST /api/v1/groups
Expand Down Expand Up @@ -153,7 +154,7 @@ func Test_can_update_a_group(t *testing.T) {
require.NoError(t, err, "Should not error when deleting a group")
}

func Test_group_user_operations(t *testing.T) {
func TestGroupUserOperations(t *testing.T) {
ctx, client, err := tests.NewClient(context.TODO())
require.NoError(t, err)
// Create a user with credentials → POST /api/v1/users?activate=false
Expand Down Expand Up @@ -218,7 +219,7 @@ func Test_group_user_operations(t *testing.T) {
require.NoError(t, err, "Should not error when deleting a group")
}

func Test_group_rule_operations(t *testing.T) {
func TestGroupRuleOperations(t *testing.T) {
t.Skip("does not work properly in test org")
ctx, client, err := tests.NewClient(context.TODO(), okta.WithCache(false))
// Create a user with credentials, activated by default → POST /api/v1/users?activate=true
Expand Down Expand Up @@ -364,3 +365,30 @@ func Test_group_rule_operations(t *testing.T) {
_, err = client.Group.DeleteGroupRule(ctx, groupRule.Id, &query.Params{})
require.NoError(t, err, "Should not error when deleting Rule")
}

func TestGroupProfileSerialization(t *testing.T) {
gp := okta.GroupProfile{
Name: "test",
Description: "tester",
GroupProfileMap: okta.GroupProfileMap{
"custom": "value",
},
}

gpExpected := okta.GroupProfile{
Name: "test",
Description: "tester",
GroupProfileMap: okta.GroupProfileMap{
"custom": "value",
},
}

b, err := json.Marshal(&gp)
require.NoError(t, err)

var gpCopy okta.GroupProfile
err = json.Unmarshal(b, &gpCopy)
require.NoError(t, err)

assert.Equal(t, gpExpected, gpCopy, "expected marshal to unmarshal to produce exact copy of group profile")
}

0 comments on commit 8d335ca

Please sign in to comment.