-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a278044
commit 5cd33f6
Showing
17 changed files
with
471 additions
and
1 deletion.
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
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
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,131 @@ | ||
{ | ||
"$id": "", | ||
"title": "Mock Definition", | ||
"description": "Describes an HTTP mock definition.", | ||
"type": "object", | ||
"properties": { | ||
"id": { "type": "string" }, | ||
"name": { "type": "string" }, | ||
"priority": { "type": "integer" }, | ||
"enabled": { "type": "boolean" }, | ||
"delay": { "oneOf": [ { "type": "string" }, { "type": "number" } ] }, | ||
"repeat": { "type": "integer" }, | ||
"scenario": { | ||
"type": "object", | ||
"properties": { | ||
"name": { "type": "string" }, | ||
"required_state": { "type": "string" }, | ||
"new_state": { "type": "string" } | ||
}, | ||
"additionalProperties": false | ||
}, | ||
"post_actions": { "type": "array", "item": { "$ref": "#/$defs/post_action" } }, | ||
"request": { | ||
"type": "object", | ||
"properties": { | ||
"scheme": { "$ref": "#/$defs/matcher" }, | ||
"method": { "$ref": "#/$defs/matcher" }, | ||
"path": { "$ref": "#/$defs/matcher" }, | ||
"url": { "$ref": "#/$defs/matcher" }, | ||
"url_match": { "$ref": "#/$defs/matcher" }, | ||
"query": { "$ref": "#/$defs/keyed_matcher" }, | ||
"queries": { "$ref": "#/$defs/keyed_matcher" }, | ||
"header": { "$ref": "#/$defs/keyed_matcher" }, | ||
"form_url_encoded": { "$ref": "#/$defs/keyed_matcher" }, | ||
"body": { "$ref": "#/$defs/matcher" } | ||
}, | ||
"additionalProperties": false | ||
}, | ||
"response": { "$ref": "#/$defs/reply" }, | ||
"response_sequence": { | ||
"type": "object", | ||
"properties": { | ||
"responses": { "type": "array", "items": { "$ref": "#/$defs/reply" } }, | ||
"after_ended": { "$ref": "#/$defs/reply" } | ||
}, | ||
"required": [ "responses" ], | ||
"additionalProperties": false | ||
}, | ||
"response_random": { | ||
"type": "object", | ||
"properties": { | ||
"responses": { "type": "array", "items": { "$ref": "#/$defs/reply" } }, | ||
"seed": { "type": "integer" } | ||
}, | ||
"required": [ "responses" ], | ||
"additionalProperties": false | ||
}, | ||
"proxy": { | ||
"type": "object", | ||
"properties": { | ||
"target": { "type": "string" }, | ||
"forward_header": { "$ref": "#/$defs/header_map" }, | ||
"header": { "$ref": "#/$defs/header_map" }, | ||
"remove_headers": { "type": "array", "items": { "type": "string" } }, | ||
"trim_prefix": { "type": "string" }, | ||
"trim_suffix": { "type": "string" }, | ||
"timeout": { "oneOf": [ { "type": "string" }, { "type": "number" } ] }, | ||
"ssl_verify": { "type": "boolean" }, | ||
"no_follow": { "type": "boolean" } | ||
}, | ||
"required": [ "target" ], | ||
"additionalProperties": false | ||
}, | ||
"ext": { "type": "object" } | ||
}, | ||
"required": [ "request" ], | ||
"additionalProperties": false, | ||
"$defs": { | ||
"matcher": { | ||
"oneOf": [ | ||
{ "type": "string" }, | ||
{ "type": "array", "minItems": 1 } | ||
] | ||
}, | ||
"keyed_matcher": { | ||
"type": "object", | ||
"patternProperties": { | ||
"^.*$": { "$ref": "#/$defs/matcher" } | ||
} | ||
}, | ||
"reply": { | ||
"type": "object", | ||
"properties": { | ||
"status": { "type": "integer" }, | ||
"header": { "$ref": "#/$defs/header_map" }, | ||
"header_template": { "$ref": "#/$defs/header_map" }, | ||
"body": { }, | ||
"body_file": { "type": "string" }, | ||
"template": { | ||
"type": "object", | ||
"properties": { | ||
"enabled": { "type": "boolean" }, | ||
"data": { "oneOf": [ { "type": "object" }, { "type": "array" } ] } | ||
} | ||
}, | ||
"encoding": { "type": "string" } | ||
} | ||
}, | ||
"post_action": { | ||
"type": "object", | ||
"properties": { | ||
"name": { "type": "string" }, | ||
"parameters": { } | ||
}, | ||
"additionalProperties": false, | ||
"required": [ "name" ] | ||
}, | ||
"string_map": { | ||
"type": "object", | ||
"patternProperties": { | ||
"^.*$": { "type": "string" } | ||
} | ||
}, | ||
"header_map": { | ||
"type": "object", | ||
"patternProperties": { | ||
"^.*$": { "oneOf": [ {"type": "string"}, {"type": "array", "items": {"type": "string"} } ] } | ||
} | ||
} | ||
} | ||
} |
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
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
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,74 @@ | ||
local header = import './http_header.libsonnet'; | ||
local mediaTypes = import './http_media_types.libsonnet'; | ||
local method = import './http_method.libsonnet'; | ||
local statuses = import './http_status.libsonnet'; | ||
local dz = import './internal/internal.libsonnet'; | ||
local scheme = import './scheme.libsonnet'; | ||
|
||
(scheme) + | ||
(method) + | ||
(header) + | ||
(mediaTypes) + | ||
(statuses) + | ||
|
||
{ | ||
mock(v):: dz.merge(v), | ||
|
||
id(id):: { id: id }, | ||
name(n):: { name: n }, | ||
priority(p):: { priority: p }, | ||
enabled(e=true):: { enabled: e }, | ||
|
||
delay(duration):: { delay: duration }, | ||
repeat(r):: { [if !std.isNumber(r) then error 'repeat must be a number' else 'repeat']: r }, | ||
scenario(name, requiredState='', newState=''):: { scenario: { name: name, [if std.isString(requiredState) && !std.isEmpty(requiredState) then 'required_state']: requiredState, [if std.isString(newState) && !std.isEmpty(newState) then 'new_state']: newState } }, | ||
|
||
request(fields):: { request: dz.merge(fields) }, | ||
req: { | ||
scheme(matcher):: { scheme: matcher }, | ||
isHTTP():: self.scheme(scheme.SchemeHTTP), | ||
isHTTPS():: self.scheme(scheme.SchemeHTTPS), | ||
|
||
method(v):: { method: if std.isString(v) then std.asciiUpper(v) else v }, | ||
get():: self.method(method.MethodGet), | ||
head():: self.method(method.MethodHead), | ||
post():: self.method(method.MethodPost), | ||
put():: self.method(method.MethodPut), | ||
patch():: self.method(method.MethodPatch), | ||
delete():: self.method(method.MethodDelete), | ||
options():: self.method(method.MethodOptions), | ||
trace():: self.method(method.MethodTrace), | ||
|
||
path(matcher):: { path: matcher }, | ||
url(matcher):: { url: matcher }, | ||
urlMatch(matcher):: { url_match: matcher }, | ||
header(key, matcher):: { header: { [key]: matcher } }, | ||
query(key, matcher):: { query: { [key]: matcher } }, | ||
queries(key, matcher):: { queries: { [key]: matcher } }, | ||
formURLEncoded(key, matcher):: { form_url_encoded: { [key]: matcher } }, | ||
body(matcher):: { body: matcher }, | ||
}, | ||
|
||
response(v):: { response: dz.merge(v) }, | ||
res: { | ||
status(code):: { status: code }, | ||
ok():: self.status(statuses.StatusOK), | ||
|
||
header(map):: { header: map }, | ||
headerTemplate(map):: { header: map }, | ||
body(b):: { body: b }, | ||
bodyFile(f):: { body_file: f }, | ||
encoding(e):: { encoding: e }, | ||
gzip():: self.encoding('gzip'), | ||
|
||
sequence(list):: { response_sequence: dz.merge(list) }, | ||
seq: { | ||
afterEnded(reply): { after_ended: reply }, | ||
}, | ||
}, | ||
|
||
postAction(name, parameters=null):: { name: name, [if std.type(parameters) != 'null' then 'parameters']: parameters }, | ||
postActions(actions):: { [if !std.isArray(actions) then error 'postActions expects an array of post actions' else 'post_actions']: actions }, | ||
|
||
ext(v):: { ext: v }, | ||
} |
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,50 @@ | ||
{ | ||
HeaderAccept: 'Accept', | ||
HeaderAcceptEncoding: 'Accept-Encoding', | ||
HeaderContentType: 'Content-Type', | ||
HeaderContentEncoding: 'Content-Encoding', | ||
HeaderAllow: 'Allow', | ||
HeaderAuthorization: 'Authorization', | ||
HeaderContentDisposition: 'Content-Disposition', | ||
HeaderVary: 'Vary', | ||
HeaderOrigin: 'Origin', | ||
HeaderContentLength: 'Content-length', | ||
HeaderConnection: 'Connection', | ||
HeaderTrailer: 'Trailer', | ||
HeaderLocation: 'Location', | ||
HeaderCacheControl: 'Cache-Control', | ||
HeaderCookie: 'Cookie', | ||
HeaderSetCookie: 'Set-Cookie', | ||
HeaderIfModifiedSince: 'If-Modified-Since', | ||
HeaderLastModified: 'Last-Modified', | ||
HeaderRetryAfter: 'Retry-After', | ||
HeaderUpgrade: 'Upgrade', | ||
HeaderWWWAuthenticate: 'WWW-Authenticate', | ||
HeaderXForwardedFor: 'X-Forwarded-For', | ||
HeaderXForwardedProto: 'X-Forwarded-Proto', | ||
HeaderXForwardedProtocol: 'X-Forwarded-Protocol', | ||
HeaderXForwardedSsl: 'X-Forwarded-Ssl', | ||
HeaderXUrlScheme: 'X-Url-Scheme', | ||
HeaderXHTTPMethodOverride: 'X-HTTP-Method-Override', | ||
HeaderXRealIP: 'X-Real-Ip', | ||
HeaderXRequestID: 'X-Request-Id', | ||
HeaderXCorrelationID: 'X-Correlation-Id', | ||
HeaderXRequestedWith: 'X-Requested-With', | ||
HeaderServer: 'Server', | ||
HeaderAccessControlRequestMethod: 'Access-Control-Request-Method', | ||
HeaderAccessControlAllowOrigin: 'Access-Control-Allow-Origin', | ||
HeaderAccessControlAllowMethods: 'Access-Control-Allow-Methods', | ||
HeaderAccessControlAllowHeaders: 'Access-Control-Allow-Header', | ||
HeaderAccessControlExposeHeaders: 'Access-Control-Expose-Header', | ||
HeaderAccessControlMaxAge: 'Access-Control-max-Age', | ||
HeaderAccessControlAllowCredentials: 'Access-Control-Allow-Credentials', | ||
HeaderAccessControlRequestHeaders: 'Access-Control-Request-Header', | ||
HeaderStrictTransportSecurity: 'Strict-Transport-Security', | ||
HeaderXContentTypeOptions: 'X-Content-Type-Options', | ||
HeaderXXSSProtection: 'X-XSS-Protection', | ||
HeaderXFrameOptions: 'X-Frame-Options', | ||
HeaderContentSecurityPolicy: 'Content-Security-Policy', | ||
HeaderContentSecurityPolicyReportOnly: 'Content-Security-Policy-Report-Only', | ||
HeaderXCSRFToken: 'X-CSRF-Token', | ||
HeaderReferrerPolicy: 'Referrer-Policy', | ||
} |
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,21 @@ | ||
local _charsetUTF8 = 'charset:UTF-8'; | ||
|
||
{ | ||
MIMEApplicationJSON: 'application/json', | ||
MIMEApplicationCharsetUTF8: self.MIMEApplicationJSON + '; ' + _charsetUTF8, | ||
MIMETextPlain: 'text/plain', | ||
MIMETextPlainCharsetUTF8: self.MIMETextPlain + '; ' + _charsetUTF8, | ||
MIMETextHTML: 'text/html', | ||
MIMETextHTMLCharsetUTF8: self.MIMETextHTML + '; ' + _charsetUTF8, | ||
MIMETextXML: 'text/xml', | ||
MIMETextXMLCharsetUTF8: self.MIMETextXML + '; ' + _charsetUTF8, | ||
MIMEFormURLEncoded: 'application/x-www-form-urlencoded', | ||
MIMEFormURLEncodedCharsetUTF8: self.MIMEFormURLEncoded + '; ' + _charsetUTF8, | ||
MIMEApplicationJavaScript: 'application/javascript', | ||
MIMEApplicationJavaScriptCharsetUTF8: self.MIMEApplicationJavaScript + '; ' + _charsetUTF8, | ||
MIMEApplicationXML: 'application/xml', | ||
MIMEApplicationXMLCharsetUTF8: self.MIMEApplicationXML + '; ' + _charsetUTF8, | ||
MIMEApplicationProtobuf: 'application/protobuf', | ||
MIMEMultipartForm: 'multipart/form-data', | ||
MIMEOctetStream: 'application/octet-stream', | ||
} |
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,10 @@ | ||
{ | ||
MethodGet: 'GET', | ||
MethodHead: 'HEAD', | ||
MethodPost: 'POST', | ||
MethodPut: 'PUT', | ||
MethodPatch: 'PATCH', | ||
MethodDelete: 'DELETE', | ||
MethodOptions: 'OPTIONS', | ||
MethodTrace: 'TRACE', | ||
} |
Oops, something went wrong.