Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 62 additions & 41 deletions CONFORMANCE.md

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions adapters/aws-s3-style/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ integration testing without a real AWS account:
`ListMultipartUploads` is not implemented, a client that has lost an upload
id cannot discover which upload is blocking the delete — `stunt reset
aws-s3-style` clears the service state.
- **Head bucket:** `HEAD /{bucket}` verifies SigV4 and bucket existence.
- **Copy object:** `PUT /{bucket}/{key}` with `x-amz-copy-source` copies bytes, content type and user metadata; `x-amz-metadata-directive: REPLACE` replaces metadata.
- **Batch delete:** `POST /{bucket}?delete` deletes up to 1000 keys from the SDK XML envelope; missing keys succeed and `Quiet` suppresses successful entries.
- **Upload object:** `PUT /{bucket}/{key}` (body = object content) → `200` with `ETag`.
- **Download object:** `GET /{bucket}/{key}` → `200` with raw body.
- **Object metadata:** `HEAD /{bucket}/{key}` → `200` with `Content-Length`, `ETag`, `Last-Modified`.
Expand Down Expand Up @@ -359,3 +362,5 @@ api:
name: "Amazon S3 API"
version: "2006-03-01"
```

CopyObject does not implement source conditions, version selection, tagging, ACL or encryption options. DeleteObjects supports the SDK Object/Key XML envelope; namespace-prefixed elements and numeric character references beyond the five XML entities are unsupported. Presigned PUT CRC32 checksum query parameters are accepted for SDK compatibility; checksum values are not verified.
8 changes: 6 additions & 2 deletions adapters/aws-s3-style/adapter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ endpoints:
- route: /{bucket}
method: GET
handler: scripts/objects.star#on_list_or_location
# Every bucket-level POST in S3 is unimplemented here — DeleteObjects
# (?delete), CreateBucketMetadataConfiguration (?metadataConfiguration),
# HeadBucket authenticated connection probe.
- route: /{bucket}
method: HEAD
handler: scripts/buckets.star#on_head_bucket
# Bucket POST implements DeleteObjects (?delete); unsupported operations
# include CreateBucketMetadataConfiguration (?metadataConfiguration),
# CreateBucketMetadataTableConfiguration (?metadataTable), and the browser
# form POST Object. Routed so the answer is S3-shaped 501 XML rather than the
# JSON catch-all 404 below.
Expand Down
19 changes: 15 additions & 4 deletions adapters/aws-s3-style/scripts/buckets.star
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ def on_create_bucket(req):
"x-amz-request-id": _req_id(),
})

# on_post_bucket handles POST /{bucket}. Every bucket-level POST in real S3 is
# unimplemented here, so the route answers 501 for all of them:
# on_post_bucket implements DeleteObjects; other bucket POST operations return 501:
# ?delete DeleteObjects (multi-object delete)
# ?metadataConfiguration CreateBucketMetadataConfiguration
# ?metadataTable CreateBucketMetadataTableConfiguration
Expand All @@ -88,8 +87,8 @@ def on_post_bucket(req):

bucket = _xml_escape(req["params"]["bucket"])
if _query_present_ci(req, "delete"):
return _xml_error("NotImplemented", "DeleteObjects (POST /{bucket}?delete) is not implemented by this simulator.", bucket, 501)
return _xml_error("NotImplemented", "No bucket-level POST is implemented by this simulator: DeleteObjects (?delete), CreateBucketMetadataConfiguration (?metadataConfiguration), CreateBucketMetadataTableConfiguration (?metadataTable) and browser form POST Object uploads are all unsupported.", bucket, 501)
return _delete_objects(req)
return _xml_error("NotImplemented", "Unsupported bucket-level POST: CreateBucketMetadataConfiguration (?metadataConfiguration), CreateBucketMetadataTableConfiguration (?metadataTable) and browser form POST Object uploads are all unsupported.", bucket, 501)

# _bucket_not_empty returns the real S3 409 BucketNotEmpty XML error. Built
# at the point of return rather than hoisted above the emptiness checks,
Expand Down Expand Up @@ -159,3 +158,15 @@ def on_delete_bucket(req):
return respond(204, "", {
"x-amz-request-id": _req_id(),
})


# HeadBucket is an authenticated existence check used by connection probes.
def on_head_bucket(req):
err = _require_auth(req)
if err != None:
return err
bucket = req["params"]["bucket"]
for b in store_collection("buckets").list():
if b.get("name", "") == bucket:
return respond(200, "", {"x-amz-bucket-region": b.get("region", "us-east-1")})
return _no_such_bucket_error(bucket)
81 changes: 78 additions & 3 deletions adapters/aws-s3-style/scripts/lib.star
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ def _reject_bucket_query(req, bucket):
# DELETE on an object are the most destructive routes in the API, and a denylist
# there would let one token added to S3 later silently re-open overwriting or
# destroying an object. Mirrors _reject_bucket_query for the same reason.
_OBJECT_WRITE_PARAMS = ["partnumber", "uploadid", "x-id"]
_OBJECT_WRITE_PARAMS = ["partnumber", "uploadid", "x-id", "x-amz-checksum-crc32", "x-amz-sdk-checksum-algorithm"]
# versionId is accepted on delete because the real SDK always sends it and,
# on a bucket with no versioning, any id addresses the single object — which is
# what real S3 does too. Without it, every versioned delete regressed from 204
Expand All @@ -901,7 +901,7 @@ _OBJECT_DELETE_PARAMS = ["uploadid", "x-id", "versionid"]
# returned 501 and the only route to clearing an in-progress upload — the thing
# that releases the 409 BucketNotEmpty on DeleteBucket — was closed off to
# every SDK client.
_OBJECT_WRITE_OPS = ["putobject", "uploadpart"]
_OBJECT_WRITE_OPS = ["putobject", "uploadpart", "copyobject"]
_OBJECT_DELETE_OPS = ["deleteobject", "abortmultipartupload"]

# POST /{bucket}/{key} carries CreateMultipartUpload (?uploads) and
Expand Down Expand Up @@ -941,7 +941,7 @@ def _query_val_ci(req, key):
# _reject_object_write_query allows only `allowed` on a mutating object route,
# and requires `x-id` to name one of `ops`. Checking the x-id VALUE matters as
# much as the key: an SDK sends `x-id=<Operation>` on every call, so allowing
# the key would let `?x-id=CopyObject` or `?x-id=RestoreObject` reach PutObject
# the key would let `?x-id=RestoreObject` reach PutObject
# or DeleteObject and mutate the object behind a mis-selected operation. Call
# it BEFORE the ?uploadId / ?partNumber multipart dispatch, so that the dispatch
# cannot be reached with a subresource the allowlist should have refused —
Expand Down Expand Up @@ -1893,3 +1893,78 @@ def _check_preconditions(req, obj, bucket, key, op):
if lm_unix <= ims_ts:
return _not_modified(cur_etag, lm_unix, lm_valid)
return None

# CopySource is a percent-encoded path, not a form/query value (+ stays +).
def _copy_source_decode(text):
raw_bytes = crypto.base64_decode(_SIG_ALL_BYTES_B64)
out = ""
i = 0
while i < len(text):
if text[i] == "%":
if i + 2 >= len(text) or not _is_hex(text[i+1:i+3]):
return None
out += raw_bytes[int(text[i+1:i+3], 16)]
i += 3
else:
out += text[i]
i += 1
return out

# Shared by single and batch deletion. Missing keys are successful no-ops.
def _delete_stored_object(bucket, key):
obj = _find_object(bucket, key)
if obj != None:
store_collection("objects").delete(obj.get("id", ""))
bid = obj.get("bid", "")
if bid:
store_blob("s3-objects").delete(bid)

# DeleteObjects accepts the same SDK XML envelope as multipart completion.
# Validate the entire key list before mutating anything.
def _delete_objects(req):
err = _require_auth(req)
if err != None:
return err
bucket = req["params"]["bucket"]
if not _query_present_ci(req, "delete"):
return _xml_error("NotImplemented", "The requested operation is not implemented", "/" + _xml_escape(bucket), 501)
for name in req.get("query", {}):
want = _ascii_lower(name)
if _is_presigned_param(name):
continue
if want not in ["delete", "x-id"] or (want == "x-id" and _ascii_lower(_query_val_ci(req, "x-id")) != "deleteobjects"):
return _xml_error("NotImplemented", "Unsupported DeleteObjects parameter", "/" + _xml_escape(bucket), 501)
found = False
for b in store_collection("buckets").list():
if b.get("name", "") == bucket:
found = True
if not found:
return _no_such_bucket_error(bucket)
raw = req.get("raw_body", "") or ""
keys = []
pos = 0
malformed = raw.find("<Delete") < 0 or raw.find("</Delete>") < 0
while True:
start = raw.find("<Object>", pos)
if start < 0:
break
end = raw.find("</Object>", start)
if end < 0:
malformed = True
break
text = _xml_tag_text(raw[start:end], "Key")
if not text:
malformed = True
keys.append(_xml_unescape(text))
pos = end + len("</Object>")
if raw.find("<VersionId>") >= 0:
return _xml_error("NotImplemented", "Versioned batch deletion is not implemented", "/" + _xml_escape(bucket), 501)
if malformed or len(keys) == 0 or len(keys) > 1000:
return _xml_error("MalformedXML", "The XML you provided was not well-formed or did not validate against our published schema", "/" + _xml_escape(bucket), 400)
quiet = _xml_tag_text(raw, "Quiet") == "true"
xml = '<DeleteResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">'
for key in keys:
_delete_stored_object(bucket, key)
if not quiet:
xml += '<Deleted><Key>' + _xml_escape(key) + '</Key></Deleted>'
return respond(200, xml + '</DeleteResult>', {"Content-Type": "application/xml", "x-amz-request-id": _req_id()})
52 changes: 40 additions & 12 deletions adapters/aws-s3-style/scripts/objects.star
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ def on_put_object(req):
if unsupported != None:
return unsupported

if _query_present_ci(req, "uploadId") and (_ascii_lower(_query_val_ci(req, "x-id")) == "copyobject" or req.get("headers", {}).get("x-amz-copy-source", "")):
return _xml_error("NotImplemented", "UploadPartCopy is not implemented", _xml_escape("/" + bucket + "/" + key), 501)

# Multipart upload part (?partNumber=N&uploadId=...).
if _query_present_ci(req, "uploadId"):
return _mpu_upload_part(req, bucket, key)
Expand All @@ -79,6 +82,11 @@ def on_put_object(req):
if bucket_doc == None:
return _no_such_bucket_error(bucket)

if req.get("headers", {}).get("x-amz-copy-source", ""):
return _copy_object(req, bucket, key)
if _ascii_lower(_query_val_ci(req, "x-id")) == "copyobject":
return _invalid_argument("x-amz-copy-source", "", "CopyObject requires a copy source")

obj = _find_object(bucket, key)
cond = _check_preconditions(req, obj, bucket, key, "put")
if cond != None:
Expand Down Expand Up @@ -222,18 +230,7 @@ def on_delete_object(req):
if cond != None:
return cond

oc = store_collection("objects")
obj_id = None
bid = None
for o in oc.list():
if o.get("bucket", "") == bucket and o.get("key", "") == key:
obj_id = o.get("id", "")
bid = o.get("bid", "")
break
if obj_id != None and obj_id != "":
oc.delete(obj_id)
if bid != None and bid != "":
store_blob("s3-objects").delete(bid)
_delete_stored_object(bucket, key)

return respond(204, "", {
"x-amz-request-id": _req_id(),
Expand Down Expand Up @@ -499,3 +496,34 @@ def _no_such_key(bucket, key):
xml = xml + "<Key>" + _xml_escape(key) + "</Key>"
xml = xml + "<RequestId>" + _req_id() + "</RequestId></Error>"
return respond(404, xml, {"Content-Type": "application/xml"})

# CopyObject returns XML even though both ordinary PUT and copy use PUT.
def _copy_object(req, bucket, key):
headers = req.get("headers", {})
source = _copy_source_decode(headers.get("x-amz-copy-source", ""))
if source == None:
return _invalid_argument("x-amz-copy-source", "", "Invalid copy source")
if source.startswith("/"):
source = source[1:]
split = source.find("/")
if split < 1:
return _invalid_argument("x-amz-copy-source", source, "Invalid copy source")
source_bucket, source_key = source[:split], source[split+1:]
obj = _find_object(source_bucket, source_key)
if obj == None:
return _no_such_key(source_bucket, source_key)
raw = store_blob("s3-objects").get(obj.get("bid", "")) or ""
directive = headers.get("x-amz-metadata-directive", "COPY")
if directive not in ["COPY", "REPLACE"]:
return _invalid_argument("x-amz-metadata-directive", directive, "Invalid metadata directive")
metadata = obj.get("metadata", {})
ct = obj.get("contentType", "application/octet-stream")
if directive == "REPLACE":
metadata, err = _collect_metadata(req)
if err != None:
return err
ct = headers.get("Content-Type", "application/octet-stream")
etag = _etag(raw)
_upsert_object(bucket, key, raw, ct, etag, metadata)
xml = '<CopyObjectResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/"><LastModified>' + _unix_to_iso8601(clock.now_unix()) + '</LastModified><ETag>"' + etag + '"</ETag></CopyObjectResult>'
return respond(200, xml, {"Content-Type": "application/xml", "x-amz-request-id": _req_id()})
2 changes: 2 additions & 0 deletions adapters/entra-id-style/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,5 @@ stunt up
```

All data is synthetic. See [DISCLAIMER](DISCLAIMER).

When `openid` is requested, token responses also include a real RS256 identity token with `oid`, `tid`, `sub`, `email`, `name`, issuer and audience claims. The synthetic tenant is `mock-tenant`. `GET /v1.0/me/photos/{size}/$value` validates the delegated bearer token then returns Graph `ImageNotFound`, modeling an account without a profile photo.
5 changes: 5 additions & 0 deletions adapters/entra-id-style/adapter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ endpoints:
method: GET
handler: scripts/oauth.star#on_jwks

# A newly created synthetic user has no profile photo.
- route: /v1.0/me/photos/{size}/$value
method: GET
handler: scripts/graph.star#on_photo

# --- Graph /me (delegated identity) ---
- route: /v1.0/me
method: GET
Expand Down
7 changes: 7 additions & 0 deletions adapters/entra-id-style/scripts/graph.star
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,10 @@ def _seed_service_principals():
]
for sp in sps:
spc.insert(sp)

# Missing photos are an ordinary Graph response, after bearer validation.
def on_photo(req):
user, err = _require_bearer(req)
if err != None:
return err
return respond(404, {"error": {"code": "ImageNotFound", "message": "No photo is stored for this user."}})
15 changes: 14 additions & 1 deletion adapters/entra-id-style/scripts/oauth.star
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def _issue_tokens(user, scope, aud):
rdoc["scope"] = scope
rc.insert(rdoc)

return {
response = {
"token_type": "Bearer",
"scope": scope,
"expires_in": 3599,
Expand All @@ -84,6 +84,10 @@ def _issue_tokens(user, scope, aud):
"refresh_token": refresh,
}

if _contains(scope, "openid"):
response["id_token"] = _mint_id_token(user, aud)
return response

# --- handlers ---

# on_authorize handles the authorization-code redirect.
Expand Down Expand Up @@ -193,3 +197,12 @@ def on_jwks(req):
key["alg"] = "RS256"
key["use"] = "sig"
return respond(200, {"keys": [key]})

# OIDC identity tokens are distinct from delegated Graph access tokens.
def _mint_id_token(user, aud):
now = clock.now_unix()
claims = {"sub": user["id"], "oid": user["id"], "tid": "mock-tenant", "name": user["displayName"], "email": user["mail"], "email_verified": True, "iss": _JWT_ISS, "aud": aud, "iat": now, "exp": now + 3599}
header = crypto.base64url_encode(json.encode({"alg": "RS256", "typ": "JWT", "kid": _JWT_KID}))
payload = crypto.base64url_encode(json.encode(claims))
signing_input = header + "." + payload
return signing_input + "." + crypto.rsa_sign(_JWT_PRIVATE_KEY, signing_input, encoding="base64url")
4 changes: 4 additions & 0 deletions adapters/github-style/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -287,3 +287,7 @@ real vocabulary) and the usual `workflow_run` `completed` delivery.

Issues, PRs, and workflow runs are seeded for `octocat/hello-world`. New records
created via POST persist for the server's lifetime.

## OAuth app sign-in

`GET /login/oauth/authorize` auto-approves a synthetic user and returns a single-use code, bound to client, redirect URI and optional PKCE verifier. `POST /login/oauth/access_token` exchanges it using form client credentials. `GET /user` and `GET /user/emails` accept that OAuth bearer token; the profile has a private email, so clients must consult the verified primary email list. OAuth clients accept any non-empty synthetic client secret; client registration, refresh/revocation and scope enforcement are not modeled. OAuth tokens are distinct from GitHub App installation tokens.
18 changes: 18 additions & 0 deletions adapters/github-style/adapter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,20 @@ api:
# NOTE: literal routes must come BEFORE parameterized routes so they are
# matched first (the dispatch engine checks in declaration order).
endpoints:
# --- OAuth app social sign-in ---
- route: /login/oauth/authorize
method: GET
handler: scripts/oauth.star#on_authorize
- route: /login/oauth/access_token
method: POST
handler: scripts/oauth.star#on_token
- route: /user
method: GET
handler: scripts/oauth.star#on_user
- route: /user/emails
method: GET
handler: scripts/oauth.star#on_emails

# --- App metadata + installation token exchange ---
- route: /app
method: GET
Expand Down Expand Up @@ -133,6 +147,10 @@ graphql:

# Backing stores — collections for stateful data.
resources:
- name: oauth_codes
kind: collection
- name: oauth_tokens
kind: collection
- name: issues
kind: collection
- name: pulls
Expand Down
Loading