Skip to content

Commit 44c9c6d

Browse files
okta-mockserver-ectomy
1 parent 86ff3e9 commit 44c9c6d

File tree

3 files changed

+213
-0
lines changed

3 files changed

+213
-0
lines changed

test/python/flask/okta/app.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
from flask import Flask, jsonify, render_template, request
2+
import os
3+
4+
app = Flask(__name__)
5+
6+
# Configure the templates directory
7+
app.template_folder = os.path.join(os.path.dirname(__file__), "templates")
8+
9+
@app.route('/api/v1/users', methods=['GET'])
10+
def get_users():
11+
"""Handles paginated user responses."""
12+
after = int(request.args.get('after', 0))
13+
end = 5
14+
next_page = after + end
15+
max_page = 45
16+
17+
users = []
18+
for i in range(after + 1, after + end + 1):
19+
users.append({
20+
"id": str(i),
21+
"status": "ACTIVE",
22+
"created": "2022-07-17T11:36:23.000Z",
23+
"activated": "2022-07-17T11:36:23.000Z",
24+
"statusChanged": "2022-07-17T11:37:06.000Z",
25+
"lastLogin": "2022-07-17T11:38:36.000Z",
26+
"lastUpdated": "2022-07-17T11:37:06.000Z",
27+
"passwordChanged": "2022-07-17T11:37:06.000Z",
28+
"type": {"id": "oty1l8curaosSnZLn697"},
29+
"profile": {
30+
"firstName": "sherlock",
31+
"lastName": "holmes",
32+
"mobilePhone": None,
33+
"secondEmail": None,
34+
"login": f"sherlockholmes{i}@gmail.com",
35+
"email": f"sherlockholmes{i}@gmail.com"
36+
},
37+
"credentials": {
38+
"password": {},
39+
"provider": {"type": "OKTA", "name": "OKTA"}
40+
},
41+
"_links": {
42+
"self": {
43+
"href": f"https://dummyorg.okta.com/api/v1/users/{i}"
44+
}
45+
}
46+
})
47+
48+
next_link = None
49+
if next_page <= max_page:
50+
next_link = f'<https://{request.host}/api/v1/users?after={next_page}>; rel="next"'
51+
52+
response_headers = {
53+
'Datetime': 'now',
54+
'Link': next_link or f'<https://{request.host}/api/v1/users?after={after}>; rel="self"'
55+
}
56+
57+
return render_template('users_template.json', users=users, headers=response_headers)
58+
59+
@app.route('/api/v1/apps', methods=['GET'])
60+
def get_apps():
61+
"""Returns app data."""
62+
apps = [
63+
{
64+
"id": "0oa3cy8k41YM15j4H5d7",
65+
"name": "saasure",
66+
"label": "Okta Admin Console",
67+
"status": "ACTIVE",
68+
"lastUpdated": "2021-12-17T15:22:44.000Z",
69+
"created": "2021-12-17T15:22:41.000Z",
70+
"visibility": {
71+
"autoSubmitToolbar": False,
72+
"hide": {"iOS": False, "web": False},
73+
"appLinks": {"admin": True}
74+
},
75+
"signOnMode": "OPENID_CONNECT",
76+
"settings": {
77+
"notifications": {"vpn": {"network": {"connection": "DISABLED"}}}
78+
},
79+
"_links": {
80+
"users": {"href": "https://dev-79923018.okta.com/api/v1/apps/0oa3cy8k41YM15j4H5d7/users"}
81+
}
82+
}
83+
]
84+
return render_template('apps_template.json', apps=apps)
85+
86+
if __name__ == '__main__':
87+
app.run(debug=True)
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
{
2+
"apps": [
3+
{% for app in apps %}
4+
{
5+
"id": "{{ app['id'] }}",
6+
"name": "{{ app['name'] }}",
7+
"label": "{{ app['label'] }}",
8+
"status": "{{ app['status'] }}",
9+
"lastUpdated": "{{ app['lastUpdated'] }}",
10+
"created": "{{ app['created'] }}",
11+
"accessibility": {
12+
"selfService": {{ app['accessibility']['selfService'] | tojson }},
13+
"errorRedirectUrl": {{ app['accessibility']['errorRedirectUrl'] | tojson }},
14+
"loginRedirectUrl": {{ app['accessibility']['loginRedirectUrl'] | tojson }}
15+
},
16+
"visibility": {
17+
"autoSubmitToolbar": {{ app['visibility']['autoSubmitToolbar'] | tojson }},
18+
"hide": {
19+
"iOS": {{ app['visibility']['hide']['iOS'] | tojson }},
20+
"web": {{ app['visibility']['hide']['web'] | tojson }}
21+
},
22+
"appLinks": {{ app['visibility']['appLinks'] | tojson }}
23+
},
24+
"features": {{ app['features'] | tojson }},
25+
"signOnMode": "{{ app['signOnMode'] }}",
26+
"credentials": {
27+
"userNameTemplate": {
28+
"template": "{{ app['credentials']['userNameTemplate']['template'] }}",
29+
"type": "{{ app['credentials']['userNameTemplate']['type'] }}"
30+
},
31+
{% if app['credentials']['signing'] %}
32+
"signing": {
33+
"kid": "{{ app['credentials']['signing']['kid'] }}"
34+
},
35+
{% endif %}
36+
{% if app['credentials']['oauthClient'] %}
37+
"oauthClient": {
38+
"autoKeyRotation": {{ app['credentials']['oauthClient']['autoKeyRotation'] | tojson }},
39+
"client_id": "{{ app['credentials']['oauthClient']['client_id'] }}",
40+
"token_endpoint_auth_method": "{{ app['credentials']['oauthClient']['token_endpoint_auth_method'] }}"
41+
}
42+
{% endif %}
43+
},
44+
"settings": {
45+
"app": {{ app['settings']['app'] | tojson }},
46+
"notifications": {
47+
"vpn": {
48+
"network": {
49+
"connection": "{{ app['settings']['notifications']['vpn']['network']['connection'] }}"
50+
},
51+
"message": {{ app['settings']['notifications']['vpn']['message'] | tojson }},
52+
"helpUrl": {{ app['settings']['notifications']['vpn']['helpUrl'] | tojson }}
53+
}
54+
},
55+
{% if app['settings']['oauthClient'] %}
56+
"oauthClient": {
57+
"client_uri": {{ app['settings']['oauthClient']['client_uri'] | tojson }},
58+
"logo_uri": {{ app['settings']['oauthClient']['logo_uri'] | tojson }},
59+
"redirect_uris": {{ app['settings']['oauthClient']['redirect_uris'] | tojson }},
60+
"response_types": {{ app['settings']['oauthClient']['response_types'] | tojson }},
61+
"grant_types": {{ app['settings']['oauthClient']['grant_types'] | tojson }},
62+
"application_type": "{{ app['settings']['oauthClient']['application_type'] }}",
63+
"consent_method": "{{ app['settings']['oauthClient']['consent_method'] }}",
64+
"issuer_mode": "{{ app['settings']['oauthClient']['issuer_mode'] }}",
65+
"idp_initiated_login": {
66+
"mode": "{{ app['settings']['oauthClient']['idp_initiated_login']['mode'] }}",
67+
"default_scope": {{ app['settings']['oauthClient']['idp_initiated_login']['default_scope'] | tojson }}
68+
},
69+
"wildcard_redirect": "{{ app['settings']['oauthClient']['wildcard_redirect'] }}"
70+
}
71+
{% endif %}
72+
},
73+
"_links": {
74+
"uploadLogo": {
75+
"href": "{{ app['_links']['uploadLogo']['href'] }}",
76+
"hints": {
77+
"allow": {{ app['_links']['uploadLogo']['hints']['allow'] | tojson }}
78+
}
79+
},
80+
"appLinks": [
81+
{% for link in app['_links']['appLinks'] %}
82+
{
83+
"name": "{{ link['name'] }}",
84+
"href": "{{ link['href'] }}",
85+
"type": "{{ link['type'] }}"
86+
}{% if not loop.last %},{% endif %}
87+
{% endfor %}
88+
],
89+
"groups": {
90+
"href": "{{ app['_links']['groups']['href'] }}"
91+
},
92+
"logo": [
93+
{% for logo in app['_links']['logo'] %}
94+
{
95+
"name": "{{ logo['name'] }}",
96+
"href": "{{ logo['href'] }}",
97+
"type": "{{ logo['type'] }}"
98+
}{% if not loop.last %},{% endif %}
99+
{% endfor %}
100+
],
101+
"users": {
102+
"href": "{{ app['_links']['users']['href'] }}"
103+
},
104+
{% if app['_links']['deactivate'] %}
105+
"deactivate": {
106+
"href": "{{ app['_links']['deactivate']['href'] }}"
107+
}
108+
{% endif %}
109+
}
110+
}{% if not loop.last %},{% endif %}
111+
{% endfor %}
112+
]
113+
}
114+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"headers": {
3+
"Datetime": "{{ headers['Datetime'] }}",
4+
"Link": "{{ headers['Link'] }}"
5+
},
6+
"body": [
7+
{% for user in users %}
8+
{{ user|tojson }}{% if not loop.last %},{% endif %}
9+
{% endfor %}
10+
]
11+
}
12+

0 commit comments

Comments
 (0)