Skip to content

Commit

Permalink
Merge pull request #1415 from GreenStage/egomes/session
Browse files Browse the repository at this point in the history
Add session_duration to access policies & orgs
  • Loading branch information
jacobbednarz committed Oct 11, 2023
2 parents a40ebf3 + 76be80a commit ceb9bd1
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
7 changes: 7 additions & 0 deletions .changelog/1415.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
access_organization: Add support for session_duration
```

```release-note:enhancement
access_policy: Add support for session_duration
```
3 changes: 3 additions & 0 deletions access_organization.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type AccessOrganization struct {
UIReadOnlyToggleReason string `json:"ui_read_only_toggle_reason,omitempty"`
UserSeatExpirationInactiveTime string `json:"user_seat_expiration_inactive_time,omitempty"`
AutoRedirectToIdentity *bool `json:"auto_redirect_to_identity,omitempty"`
SessionDuration *string `json:"session_duration,omitempty"`
CustomPages AccessOrganizationCustomPages `json:"custom_pages,omitempty"`
}

Expand Down Expand Up @@ -64,6 +65,7 @@ type CreateAccessOrganizationParams struct {
UIReadOnlyToggleReason string `json:"ui_read_only_toggle_reason,omitempty"`
UserSeatExpirationInactiveTime string `json:"user_seat_expiration_inactive_time,omitempty"`
AutoRedirectToIdentity *bool `json:"auto_redirect_to_identity,omitempty"`
SessionDuration *string `json:"session_duration,omitempty"`
CustomPages AccessOrganizationCustomPages `json:"custom_pages,omitempty"`
}

Expand All @@ -75,6 +77,7 @@ type UpdateAccessOrganizationParams struct {
UIReadOnlyToggleReason string `json:"ui_read_only_toggle_reason,omitempty"`
UserSeatExpirationInactiveTime string `json:"user_seat_expiration_inactive_time,omitempty"`
AutoRedirectToIdentity *bool `json:"auto_redirect_to_identity,omitempty"`
SessionDuration *string `json:"session_duration,omitempty"`
CustomPages AccessOrganizationCustomPages `json:"custom_pages,omitempty"`
}

Expand Down
18 changes: 14 additions & 4 deletions access_organization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func TestAccessOrganization(t *testing.T) {
"is_ui_read_only": false,
"user_seat_expiration_inactive_time": "720h",
"auto_redirect_to_identity": true,
"session_duration": "12h",
"login_design": {
"background_color": "#c5ed1b",
"logo_path": "https://example.com/logo.png",
Expand Down Expand Up @@ -57,6 +58,7 @@ func TestAccessOrganization(t *testing.T) {
FooterText: "© Widget Corp",
},
IsUIReadOnly: BoolPtr(false),
SessionDuration: StringPtr("12h"),
UserSeatExpirationInactiveTime: "720h",
AutoRedirectToIdentity: BoolPtr(true),
}
Expand Down Expand Up @@ -95,6 +97,7 @@ func TestCreateAccessOrganization(t *testing.T) {
"name": "Widget Corps Internal Applications",
"auth_domain": "test.cloudflareaccess.com",
"is_ui_read_only": true,
"session_duration": "12h",
"login_design": {
"background_color": "#c5ed1b",
"logo_path": "https://example.com/logo.png",
Expand Down Expand Up @@ -122,7 +125,8 @@ func TestCreateAccessOrganization(t *testing.T) {
HeaderText: "Widget Corp",
FooterText: "© Widget Corp",
},
IsUIReadOnly: BoolPtr(true),
IsUIReadOnly: BoolPtr(true),
SessionDuration: StringPtr("12h"),
}

mux.HandleFunc("/accounts/"+testAccountID+"/access/organizations", handler)
Expand All @@ -137,7 +141,8 @@ func TestCreateAccessOrganization(t *testing.T) {
HeaderText: "Widget Corp",
FooterText: "© Widget Corp",
},
IsUIReadOnly: BoolPtr(true),
IsUIReadOnly: BoolPtr(true),
SessionDuration: StringPtr("12h"),
})

if assert.NoError(t, err) {
Expand All @@ -156,7 +161,8 @@ func TestCreateAccessOrganization(t *testing.T) {
HeaderText: "Widget Corp",
FooterText: "© Widget Corp",
},
IsUIReadOnly: BoolPtr(true),
IsUIReadOnly: BoolPtr(true),
SessionDuration: StringPtr("12h"),
})

if assert.NoError(t, err) {
Expand Down Expand Up @@ -188,7 +194,8 @@ func TestUpdateAccessOrganization(t *testing.T) {
"footer_text": "© Widget Corp"
},
"is_ui_read_only": false,
"ui_read_only_toggle_reason": "this is my reason"
"ui_read_only_toggle_reason": "this is my reason",
"session_duration": "12h"
}
}
`)
Expand All @@ -211,6 +218,7 @@ func TestUpdateAccessOrganization(t *testing.T) {
},
IsUIReadOnly: BoolPtr(false),
UIReadOnlyToggleReason: "this is my reason",
SessionDuration: StringPtr("12h"),
}

mux.HandleFunc("/accounts/"+testAccountID+"/access/organizations", handler)
Expand All @@ -226,6 +234,7 @@ func TestUpdateAccessOrganization(t *testing.T) {
FooterText: "© Widget Corp",
},
IsUIReadOnly: BoolPtr(false),
SessionDuration: StringPtr("12h"),
UIReadOnlyToggleReason: "this is my reason",
})

Expand All @@ -247,6 +256,7 @@ func TestUpdateAccessOrganization(t *testing.T) {
},
IsUIReadOnly: BoolPtr(false),
UIReadOnlyToggleReason: "this is my reason",
SessionDuration: StringPtr("12h"),
})

if assert.NoError(t, err) {
Expand Down
3 changes: 3 additions & 0 deletions access_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type AccessPolicy struct {
Name string `json:"name"`

IsolationRequired *bool `json:"isolation_required,omitempty"`
SessionDuration *string `json:"session_duration,omitempty"`
PurposeJustificationRequired *bool `json:"purpose_justification_required,omitempty"`
PurposeJustificationPrompt *string `json:"purpose_justification_prompt,omitempty"`
ApprovalRequired *bool `json:"approval_required,omitempty"`
Expand Down Expand Up @@ -84,6 +85,7 @@ type CreateAccessPolicyParams struct {
Name string `json:"name"`

IsolationRequired *bool `json:"isolation_required,omitempty"`
SessionDuration *string `json:"session_duration,omitempty"`
PurposeJustificationRequired *bool `json:"purpose_justification_required,omitempty"`
PurposeJustificationPrompt *string `json:"purpose_justification_prompt,omitempty"`
ApprovalRequired *bool `json:"approval_required,omitempty"`
Expand Down Expand Up @@ -111,6 +113,7 @@ type UpdateAccessPolicyParams struct {
Name string `json:"name"`

IsolationRequired *bool `json:"isolation_required,omitempty"`
SessionDuration *string `json:"session_duration,omitempty"`
PurposeJustificationRequired *bool `json:"purpose_justification_required,omitempty"`
PurposeJustificationPrompt *string `json:"purpose_justification_prompt,omitempty"`
ApprovalRequired *bool `json:"approval_required,omitempty"`
Expand Down
10 changes: 10 additions & 0 deletions access_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ var (
map[string]interface{}{"email": map[string]interface{}{"email": "test@example.com"}},
},
IsolationRequired: &isolationRequired,
SessionDuration: StringPtr("12h"),
PurposeJustificationRequired: &purposeJustificationRequired,
ApprovalRequired: &approvalRequired,
PurposeJustificationPrompt: &purposeJustificationPrompt,
Expand Down Expand Up @@ -101,6 +102,7 @@ func TestAccessPolicies(t *testing.T) {
"purpose_justification_required": true,
"purpose_justification_prompt": "Please provide a business reason for your need to access before continuing.",
"approval_required": true,
"session_duration": "12h",
"approval_groups": [
{
"email_list_uuid": "2413b6d7-bbe5-48bd-8fbb-e52069c85561",
Expand Down Expand Up @@ -185,6 +187,7 @@ func TestAccessPolicy(t *testing.T) {
"purpose_justification_required": true,
"purpose_justification_prompt": "Please provide a business reason for your need to access before continuing.",
"approval_required": true,
"session_duration": "12h",
"approval_groups": [
{
"email_list_uuid": "2413b6d7-bbe5-48bd-8fbb-e52069c85561",
Expand Down Expand Up @@ -260,6 +263,7 @@ func TestCreateAccessPolicy(t *testing.T) {
"purpose_justification_required": true,
"purpose_justification_prompt": "Please provide a business reason for your need to access before continuing.",
"approval_required": true,
"session_duration": "12h",
"approval_groups": [
{
"email_list_uuid": "2413b6d7-bbe5-48bd-8fbb-e52069c85561",
Expand Down Expand Up @@ -296,6 +300,7 @@ func TestCreateAccessPolicy(t *testing.T) {
Decision: "allow",
PurposeJustificationRequired: &purposeJustificationRequired,
PurposeJustificationPrompt: &purposeJustificationPrompt,
SessionDuration: StringPtr("12h"),
ApprovalGroups: []AccessApprovalGroup{
{
EmailListUuid: "2413b6d7-bbe5-48bd-8fbb-e52069c85561",
Expand Down Expand Up @@ -328,6 +333,7 @@ func TestCreateAccessPolicy(t *testing.T) {
func TestCreateAccessPolicyAuthContextRule(t *testing.T) {
setup()
defer teardown()

expectedAccessPolicyAuthContext := AccessPolicy{
ID: "699d98642c564d2e855e9661899b7252",
Precedence: 1,
Expand All @@ -346,6 +352,7 @@ func TestCreateAccessPolicyAuthContextRule(t *testing.T) {
PurposeJustificationRequired: &purposeJustificationRequired,
ApprovalRequired: &approvalRequired,
PurposeJustificationPrompt: &purposeJustificationPrompt,
SessionDuration: StringPtr("12h"),
ApprovalGroups: []AccessApprovalGroup{
{
EmailListUuid: "2413b6d7-bbe5-48bd-8fbb-e52069c85561",
Expand Down Expand Up @@ -393,6 +400,7 @@ func TestCreateAccessPolicyAuthContextRule(t *testing.T) {
"purpose_justification_required": true,
"purpose_justification_prompt": "Please provide a business reason for your need to access before continuing.",
"approval_required": true,
"session_duration": "12h",
"approval_groups": [
{
"email_list_uuid": "2413b6d7-bbe5-48bd-8fbb-e52069c85561",
Expand Down Expand Up @@ -483,6 +491,7 @@ func TestUpdateAccessPolicy(t *testing.T) {
PurposeJustificationRequired: &purposeJustificationRequired,
ApprovalRequired: &approvalRequired,
PurposeJustificationPrompt: &purposeJustificationPrompt,
SessionDuration: StringPtr("12h"),
ApprovalGroups: []AccessApprovalGroup{
{
EmailListUuid: "2413b6d7-bbe5-48bd-8fbb-e52069c85561",
Expand All @@ -508,6 +517,7 @@ func TestUpdateAccessPolicy(t *testing.T) {
"created_at": "2014-01-01T05:20:00.12345Z",
"updated_at": "2014-01-01T05:20:00.12345Z",
"name": "Allow devs",
"session_duration": "12h",
"include": [
{
"email": {
Expand Down

0 comments on commit ceb9bd1

Please sign in to comment.