-
Notifications
You must be signed in to change notification settings - Fork 3
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 #127 from ba-st/126-Access-Control-Allow-Origin-sh…
…ould-match-the-Origin- force Access-Control-Allow-Origin to have a valid origin format
- Loading branch information
Showing
10 changed files
with
191 additions
and
24 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
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,45 @@ | ||
Class { | ||
#name : #WebOriginTest, | ||
#superclass : #TestCase, | ||
#category : #'Stargate-Model-Tests-Routing' | ||
} | ||
|
||
{ #category : #tests } | ||
WebOriginTest >> testComparing [ | ||
|
||
self assert: 'http://example.com/' asWebOrigin hash equals: 'http://example.com' hash. | ||
self assert: 'http://example.com/' asWebOrigin equals: 'http://example.com'. | ||
self assert: 'http://example.com:80/' asWebOrigin equals: 'http://example.com'. | ||
self assert: 'http://example.com/path/file' asWebOrigin equals: 'http://example.com'. | ||
self assert: 'http://example.com:8080/' asWebOrigin equals: 'http://example.com:8080'. | ||
self assert: 'http://www.example.com/' asWebOrigin equals: 'http://www.example.com'. | ||
self assert: 'https://example.com:443/' asWebOrigin equals: 'https://example.com'. | ||
self assert: 'https://example.com/' asWebOrigin equals: 'https://example.com'. | ||
self assert: 'http://example.org/' asWebOrigin equals: 'http://example.org'. | ||
self assert: 'http://ietf.org/' asWebOrigin equals: 'http://ietf.org'. | ||
self assert: 'http://127.0.0.1:8081/the/path/' asWebOrigin equals: 'http://127.0.0.1:8081'. | ||
self assert: 'https://[email protected]:123/forum/questions?id=1' asWebOrigin equals: 'https://www.example.com:123'. | ||
self | ||
should: [ 'mailto:[email protected]' asWebOrigin ] | ||
raise: InstanceCreationFailed | ||
withMessageText: 'mailto:[email protected] does not comply with a valid origin' | ||
] | ||
|
||
{ #category : #tests } | ||
WebOriginTest >> testValidOrigins [ | ||
|
||
self assert: 'http://example.com/' asUrl hasValidOrigin. | ||
self assert: 'http://example.com:80/' asUrl hasValidOrigin. | ||
self assert: 'http://example.com/path/file' asUrl hasValidOrigin. | ||
self assert: 'http://example.com:8080/' asUrl hasValidOrigin. | ||
self assert: 'http://www.example.com/' asUrl hasValidOrigin. | ||
self assert: 'https://example.com:80/' asUrl hasValidOrigin. | ||
self assert: 'https://example.com/' asUrl hasValidOrigin. | ||
self assert: 'http://example.org/' asUrl hasValidOrigin. | ||
self assert: 'http://ietf.org/' asUrl hasValidOrigin. | ||
self assert: 'http://127.0.0.1:8081/the/path/' asUrl hasValidOrigin. | ||
self assert: 'https://[email protected]:123/forum/questions?id=1' asUrl hasValidOrigin. | ||
self assert: 'https://[email protected]:123/forum/questions?id=1' asUrl hasValidOrigin. | ||
self deny: 'mailto:[email protected]' asUrl hasValidOrigin. | ||
|
||
] |
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
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,7 @@ | ||
Extension { #name : #String } | ||
|
||
{ #category : #'*Stargate-Model' } | ||
String >> asWebOrigin [ | ||
|
||
^ self asUrl asWebOrigin | ||
] |
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 @@ | ||
" | ||
I represent a web origin as defined in the RFC 6454. | ||
I have the format | ||
scheme '://' host [ ':' port ] | ||
with <scheme>, <host>, <port> from RFC 3986. | ||
The // precedes the authority component of the uri, and thus I accept the schemes | ||
that may have the authority component. Currently #(http https) but this can be extended at will. | ||
References | ||
https://tools.ietf.org/html/rfc6454 | ||
https://tools.ietf.org/html/rfc3986 | ||
" | ||
Class { | ||
#name : #WebOrigin, | ||
#superclass : #Object, | ||
#instVars : [ | ||
'url' | ||
], | ||
#category : #'Stargate-Model-CORS' | ||
} | ||
|
||
{ #category : #'instance creation' } | ||
WebOrigin class >> basedOn: aUrl [ | ||
|
||
AssertionChecker | ||
enforce: [ self hasValidOrigin: aUrl ] | ||
because: [ '<1p> does not comply with a valid origin' expandMacrosWith: aUrl ] | ||
raising: InstanceCreationFailed. | ||
|
||
^ self new initializeBasedOn: aUrl | ||
] | ||
|
||
{ #category : #preconditions } | ||
WebOrigin class >> hasValidOrigin: aUrl [ | ||
|
||
| validOriginSchemes | | ||
|
||
validOriginSchemes := #(#http #https). | ||
|
||
^ aUrl hasScheme and: [ ( validOriginSchemes includes: aUrl scheme ) and: [ aUrl hasHost ] ] | ||
] | ||
|
||
{ #category : #comparing } | ||
WebOrigin >> = aWebOrigin [ | ||
|
||
^ self asString = aWebOrigin asString | ||
] | ||
|
||
{ #category : #comparing } | ||
WebOrigin >> hash [ | ||
|
||
^ self asString hash | ||
] | ||
|
||
{ #category : #initialization } | ||
WebOrigin >> initializeBasedOn: aUrl [ | ||
|
||
url := aUrl | ||
] | ||
|
||
{ #category : #printing } | ||
WebOrigin >> printOn: stream [ | ||
|
||
stream | ||
nextPutAll: url scheme; | ||
nextPutAll: '://'; | ||
nextPutAll: url host. | ||
url hasNonDefaultPort | ||
then: [ stream | ||
nextPut: $:; | ||
print: url port | ||
] | ||
] |
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,13 @@ | ||
Extension { #name : #ZnUrl } | ||
|
||
{ #category : #'*Stargate-Model' } | ||
ZnUrl >> asWebOrigin [ | ||
|
||
^ WebOrigin basedOn: self | ||
] | ||
|
||
{ #category : #'*Stargate-Model' } | ||
ZnUrl >> hasValidOrigin [ | ||
|
||
^ WebOrigin hasValidOrigin: self | ||
] |