Skip to content

Commit

Permalink
Merge pull request #257 from alexwilcox9/authstrengthpolicy
Browse files Browse the repository at this point in the history
Add `updateAllowedCombinations` to `AuthenticationStrengthPoliciesClient`
  • Loading branch information
manicminer authored Sep 25, 2023
2 parents 6cb3502 + e0d6330 commit c04c5dd
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
36 changes: 36 additions & 0 deletions msgraph/authentication_strength_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,42 @@ func (c *AuthenticationStrengthPoliciesClient) Update(ctx context.Context, Authe
return status, nil
}

// Update amends an existing AuthenticationStrengthPolicy's allowed combinations
func (c *AuthenticationStrengthPoliciesClient) UpdateAllowedCombinations(ctx context.Context, policy AuthenticationStrengthPolicy) (int, error) {
var status int

if policy.ID == nil {
return status, errors.New("cannot update AuthenticationStrengthPolicy with nil ID")
}

if policy.AllowedCombinations == nil {
return status, errors.New("cannot update AuthenticationStrengthPolicy with nil AllowedCombinations")
}

allowedCombinations := AuthenticationStrengthPolicy{
AllowedCombinations: policy.AllowedCombinations,
}

body, err := json.Marshal(allowedCombinations)
if err != nil {
return status, fmt.Errorf("json.Marshal(): %v", err)
}

_, status, _, err = c.BaseClient.Post(ctx, PostHttpRequestInput{
Body: body,
ConsistencyFailureFunc: RetryOn404ConsistencyFailureFunc,
ValidStatusCodes: []int{http.StatusOK},
Uri: Uri{
Entity: fmt.Sprintf("/policies/authenticationStrengthPolicies/%s/updateAllowedCombinations", *policy.ID),
},
})
if err != nil {
return status, fmt.Errorf("AuthenticationStrengthPoliciesClient.BaseClient.Post(): %v", err)
}

return status, nil
}

// Delete removes a AuthenticationStrengthPolicy.
func (c *AuthenticationStrengthPoliciesClient) Delete(ctx context.Context, id string) (int, error) {
_, status, _, err := c.BaseClient.Delete(ctx, DeleteHttpRequestInput{
Expand Down
18 changes: 18 additions & 0 deletions msgraph/authentication_strength_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ func TestAuthenticationStrengthPolicyClient(t *testing.T) {
}
testAuthenticationStrengthPoliciesClient_Update(t, c, updatePolicy)

updateAllowedCombinations := msgraph.AuthenticationStrengthPolicy{
ID: policy.ID,
DisplayName: utils.StringPtr(fmt.Sprintf("test-policy-updated-%s", c.RandomString)),
AllowedCombinations: &[]string{"password, hardwareOath", "deviceBasedPush"},
}

testAuthenticationStrengthPoliciesClient_UpdateAllowedCombinations(t, c, updateAllowedCombinations)

testAuthenticationStrengthPoliciesClient_List(t, c)
testAuthenticationStrengthPoliciesClient_Get(t, c, *policy.ID)
testAuthenticationStrengthPoliciesClient_Delete(t, c, *policy.ID)
Expand Down Expand Up @@ -74,6 +82,16 @@ func testAuthenticationStrengthPoliciesClient_Update(t *testing.T, c *test.Test,
}
}

func testAuthenticationStrengthPoliciesClient_UpdateAllowedCombinations(t *testing.T, c *test.Test, policy msgraph.AuthenticationStrengthPolicy) {
status, err := c.AuthenticationStrengthPoliciesClient.UpdateAllowedCombinations(c.Context, policy)
if err != nil {
t.Fatalf("AuthenticationStrengthPolicyClient.UpdateAllowedCombinations(): %v", err)
}
if status < 200 || status >= 300 {
t.Fatalf("AuthenticationStrengthPolicyClient.UpdateAllowedCombinations(): invalid status: %d", status)
}
}

func testAuthenticationStrengthPoliciesClient_List(t *testing.T, c *test.Test) (policies *[]msgraph.AuthenticationStrengthPolicy) {
policies, _, err := c.AuthenticationStrengthPoliciesClient.List(c.Context, odata.Query{})
if err != nil {
Expand Down

0 comments on commit c04c5dd

Please sign in to comment.