This repository has been archived by the owner on Feb 16, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #214 from Widcket/feature/anomaly
Add support for Anomaly endpoints
- Loading branch information
Showing
3 changed files
with
80 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package management | ||
|
||
import ( | ||
"net/http" | ||
) | ||
|
||
type AnomalyManager struct { | ||
*Management | ||
} | ||
|
||
func newAnomalyManager(m *Management) *AnomalyManager { | ||
return &AnomalyManager{m} | ||
} | ||
|
||
// Check if a given IP address is blocked via the multiple user accounts | ||
// trigger due to multiple failed logins. | ||
// | ||
// See: https://auth0.com/docs/api/management/v2#!/Anomaly/get_ips_by_id | ||
func (m *AnomalyManager) CheckIP(ip string, opts ...RequestOption) (isBlocked bool, err error) { | ||
req, err := m.NewRequest("GET", m.URI("anomaly", "blocks", "ips", ip), nil, opts...) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
res, err := m.Do(req) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
// 200: IP address specified is currently blocked. | ||
if res.StatusCode == http.StatusOK { | ||
return true, nil | ||
} | ||
|
||
// 404: IP address specified is not currently blocked. | ||
if res.StatusCode == http.StatusNotFound { | ||
return false, nil | ||
} | ||
|
||
return false, newError(res.Body) | ||
} | ||
|
||
// Unblock an IP address currently blocked by the multiple user accounts | ||
// trigger due to multiple failed logins. | ||
// | ||
// See: https://auth0.com/docs/api/management/v2#!/Anomaly/delete_ips_by_id | ||
func (m *AnomalyManager) UnblockIP(ip string, opts ...RequestOption) (err error) { | ||
return m.Request("DELETE", m.URI("anomaly", "blocks", "ips", ip), nil, opts...) | ||
} |
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,27 @@ | ||
package management | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestAnomaly(t *testing.T) { | ||
|
||
t.Run("CheckIP", func(t *testing.T) { | ||
isBlocked, err := m.Anomaly.CheckIP("1.1.1.1") | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
if isBlocked { | ||
t.Error(fmt.Errorf("IP should not be blocked")) | ||
} | ||
}) | ||
|
||
t.Run("UnblockIP", func(t *testing.T) { | ||
err := m.Anomaly.UnblockIP("1.1.1.1") | ||
if err != nil { | ||
t.Error(err) | ||
} | ||
}) | ||
|
||
} |
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