Skip to content

Commit 52dc5d9

Browse files
- Testing scaffold in place.
1 parent 6ef4c82 commit 52dc5d9

File tree

7 files changed

+762
-4
lines changed

7 files changed

+762
-4
lines changed

cicd/version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
MajorVersion=0
2-
MinorVersion=5
2+
MinorVersion=6

test/mockserver/expectations/static-auth-testing-expectations.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,35 @@
4545
}]
4646
}
4747
}
48+
},
49+
{
50+
"httpRequest": {
51+
"method": "GET",
52+
"path": "/v1/collectors/100000001",
53+
"headers": {
54+
"Authorization": ["^Bearer\\ 1/8xbJqaOZXSUZbHLl5EOtu1pxz3fmmetKx9W8CV4t79M$" ]
55+
}
56+
},
57+
"httpResponse": {
58+
"body": {
59+
"collector": {
60+
"id":100000001,
61+
"name":"Netlify",
62+
"category":"netlify",
63+
"timeZone":"Australia/Melbourne",
64+
"fields":{
65+
66+
},
67+
"links":[{
68+
"rel":"sources",
69+
"href":"/v1/collectors/100000001/sources"
70+
}],
71+
"collectorType":"Hosted",
72+
"collectorVersion":"",
73+
"lastSeenAlive":1670366500147,
74+
"alive":true
75+
}
76+
}
77+
}
4878
}
4979
]

test/python/flask/oauth2/token_srv.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from flask import Flask, request
22

3+
from werkzeug.datastructures import ImmutableMultiDict
4+
35
import json
46

57
import base64
@@ -53,16 +55,17 @@ def generate_google_response_dict(self, default_scopes: List[str]=["https://www.
5355
"expires_in": 3600
5456
}
5557

58+
# conforming to [RFC 6749](https://datatracker.ietf.org/doc/html/rfc6749#section-5.1)
5659
_SIMPLE_RESPONSE = {
5760
"access_token": "1/8xbJqaOZXSUZbHLl5EOtu1pxz3fmmetKx9W8CV4t79M",
5861
"scope": 'my-scope',
5962
"token_type": "Bearer",
63+
"refresh_token": "1/9xbJqaOZXSUZbHLl5EOtu1pxz3fmmetKx9W8CV4t79M", # optional, per the RFC
6064
"expires_in": 3600
6165
}
6266

63-
@app.route("/")
64-
def hello_world():
65-
return "<p>Hello, World!</p>"
67+
def _form_to_str(form: ImmutableMultiDict) -> str:
68+
return json.dumps(form.to_dict(flat=False), sort_keys=True)
6669

6770
@app.route("/google/simple/token", methods=['POST'])
6871
def google_simple_token():
@@ -79,4 +82,5 @@ def google_simple_error_token():
7982
@app.route("/contrived/simple/token", methods=['POST'])
8083
def contrived_simple_token():
8184
request_data = request.form
85+
app.logger.info(f'POST /contrived/simple/token request data: {_form_to_str(request_data)}')
8286
return json.dumps(_SIMPLE_RESPONSE, sort_keys=True)

test/python/registry-rewrite.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
from pathlib import Path
66

7+
import urllib.parse
8+
79
import shutil
810
import yaml
911

@@ -131,6 +133,11 @@ def __init__(self, name :str, srcdir :str, destdir :str, port :int, replacement_
131133

132134
def isServerRewriteRequired(self) -> bool:
133135
return self.name != 'k8s'
136+
137+
def _replace_token_url(url :str, replacement_host :str) -> str:
138+
parsed = urllib.parse.urlparse(url)
139+
replaced = parsed._replace(netloc="{}:{}".format(replacement_host, parsed.port))
140+
return urllib.parse.urlunparse(replaced)
134141

135142
def rewrite_provider(args :ProviderArgs):
136143
os.chdir(args.srcdir)
@@ -146,6 +153,9 @@ def rewrite_provider(args :ProviderArgs):
146153
for srv in servs:
147154
srv['url'] = f'https://{args.replacement_host}:{args.port}/'
148155
d['servers'] = servs
156+
token_url = d.get('config', {}).get('auth', {}).get('token_url')
157+
if args.isServerRewriteRequired() and token_url:
158+
d['config']['auth']['token_url'] = _replace_token_url(token_url, args.replacement_host)
149159
for path, path_item in d.get('paths', {}).items():
150160
path_item_servers = path_item.get('servers', [])
151161
if args.isServerRewriteRequired():
@@ -208,6 +218,9 @@ def __init__(self, processed_args :argparse.Namespace) -> None:
208218
"stackql_auth_testing": {
209219
"port": processed_args.stackql_auth_testing_port
210220
},
221+
"stackql_oauth2_testing": {
222+
"port": processed_args.stackql_auth_testing_port # shared port acceptable coz auth server decooupled for outh2
223+
},
211224
"__default__": {
212225
"port": processed_args.default_port
213226
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
id: stackql_oauth2_testing
2+
name: stackql_oauth2_testing
3+
version: v0.1.0
4+
providerServices:
5+
collectors:
6+
description: Interact with and view information about collectors.
7+
id: collectors:v0.1.0
8+
name: collectors
9+
preferred: true
10+
service:
11+
$ref: stackql_oauth2_testing/v0.1.0/services/collectors.yaml
12+
title: Sumo Logic v1 REST API - users
13+
version: v0.1.0
14+
users:
15+
description: Interact with and view information about users.
16+
id: users:v0.1.0
17+
name: users
18+
preferred: true
19+
service:
20+
$ref: stackql_oauth2_testing/v0.1.0/services/users.yaml
21+
title: Sumo Logic v1 REST API - users
22+
version: v0.1.0
23+
openapi: 3.0.3
24+
config:
25+
auth:
26+
client_id_env_var: 'YOUR_OAUTH2_CLIENT_ID_ENV_VAR'
27+
client_secret_env_var: 'YOUR_OAUTH2_CLIENT_SECRET_ENV_VAR'
28+
type: "oauth2"
29+
grant_type: "client_credentials"
30+
token_url: 'http://localhost:2091/contrived/simple/token'
31+
scopes:
32+
- 'scope-01'
33+
- 'scope-02'

0 commit comments

Comments
 (0)