This repository has been archived by the owner on Apr 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#3, test: Integration test for security constraints
- Loading branch information
1 parent
642696a
commit 213388a
Showing
6 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
compiler/src/test/resources/expected_results/security_constraints/basic.auth.api.yaml.types
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 @@ | ||
BasicConstraint(Basic(Some(HTTP Basic Authentication. Works over `HTTP` and `HTTPS`))) |
2 changes: 2 additions & 0 deletions
2
...ler/src/test/resources/expected_results/security_constraints/full.petstore.api.yaml.types
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,2 @@ | ||
OAuth2Constraint(OAuth2Implicit(None,http://petstore.swagger.wordnik.com/api/oauth/dialog,Map(write_pets -> modify pets in your account, read_pets -> read your pets)),Set(write_pets, read_pets)) | ||
ApiKeyConstraint(ApiKey(None,api_key,header)) |
13 changes: 13 additions & 0 deletions
13
compiler/src/test/resources/expected_results/security_constraints/instagram.api.yaml.types
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 @@ | ||
OAuth2Constraint(OAuth2Implicit(None,https://instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=token,Map(basic -> to read any and all data related to a user (e.g. following/followed-by | ||
lists, photos, etc.) (granted by default) | ||
, comments -> to create or delete comments on a user’s behalf, relationships -> to follow and unfollow users on a user’s behalf, likes -> to like and unlike items on a user’s behalf)),Set(basic, comments, relationships, likes)) | ||
ApiKeyConstraint(ApiKey(None,access_token,query)) | ||
OAuth2Constraint(OAuth2Implicit(None,https://instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=token,Map(basic -> to read any and all data related to a user (e.g. following/followed-by | ||
lists, photos, etc.) (granted by default) | ||
, comments -> to create or delete comments on a user’s behalf, relationships -> to follow and unfollow users on a user’s behalf, likes -> to like and unlike items on a user’s behalf)),Set(comments)) | ||
OAuth2Constraint(OAuth2Implicit(None,https://instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=token,Map(basic -> to read any and all data related to a user (e.g. following/followed-by | ||
lists, photos, etc.) (granted by default) | ||
, comments -> to create or delete comments on a user’s behalf, relationships -> to follow and unfollow users on a user’s behalf, likes -> to like and unlike items on a user’s behalf)),Set(relationships)) | ||
OAuth2Constraint(OAuth2Implicit(None,https://instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=token,Map(basic -> to read any and all data related to a user (e.g. following/followed-by | ||
lists, photos, etc.) (granted by default) | ||
, comments -> to create or delete comments on a user’s behalf, relationships -> to follow and unfollow users on a user’s behalf, likes -> to like and unlike items on a user’s behalf)),Set(basic)) |
2 changes: 2 additions & 0 deletions
2
compiler/src/test/resources/expected_results/security_constraints/security.api.yaml.types
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,2 @@ | ||
OAuth2Constraint(OAuth2AccessCode(None,https://github.com/login/oauth/authorize,https://github.com/login/oauth/access_token,Map(admin:org -> Fully manage organization, teams, and memberships., user:email -> Grants read access to a user’s email addresses., read:org -> Read-only access to organization, teams, and membership., public_repo -> Grants read/write access to code, commit statuses, and deployment statuses for public repositories and organizations., write:public_key -> Create, list, and view details for public keys., repo_deployment -> Grants access to deployment statuses for public and private repositories. This scope is only necessary to grant other users or services access to deployment statuses, without granting access to the code., write:repo_hook -> Grants read, write, and ping access to hooks in public or private repositories., admin:public_key -> Fully manage public keys., repo:status -> Grants read/write access to public and private repository commit statuses. This scope is only necessary to grant other users or services access to private repository commit statuses without granting access to the code., gist -> Grants write access to gists., user:follow -> Grants access to follow or unfollow other users., repo -> Grants read/write access to code, commit statuses, and deployment statuses for public and private repositories and organizations., read:repo_hook -> Grants read and ping access to hooks in public or private repositories., notifications -> Grants read access to a user’s notifications. repo also provides this access., read:public_key -> List and view details for public keys., admin:repo_hook -> Grants read, write, ping, and delete access to hooks in public or private repositories., user -> Grants read/write access to profile info only. Note that this scope includes user:email and user:follow., write:org -> Publicize and unpublicize organization membership., delete_repo -> Grants access to delete adminable repositories.)),Set(user)) | ||
ApiKeyConstraint(ApiKey(None,api_key,header)) |
2 changes: 2 additions & 0 deletions
2
...er/src/test/resources/expected_results/security_constraints/split.petstore.api.yaml.types
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,2 @@ | ||
OAuth2Constraint(OAuth2Implicit(None,http://petstore.swagger.wordnik.com/api/oauth/dialog,Map(write_pets -> modify pets in your account, read_pets -> read your pets)),Set(write_pets, read_pets)) | ||
ApiKeyConstraint(ApiKey(None,api_key,header)) |
36 changes: 36 additions & 0 deletions
36
compiler/src/test/scala/de/zalando/swagger/SecurityConstraintsIntegrationTest.scala
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,36 @@ | ||
package de.zalando.swagger | ||
|
||
import java.io.File | ||
|
||
import de.zalando.ExpectedResults | ||
import org.scalatest.{FunSpec, MustMatchers} | ||
|
||
/** | ||
* @since 05.03.2016 | ||
*/ | ||
class SecurityConstraintsIntegrationTest extends FunSpec with MustMatchers with ExpectedResults { | ||
|
||
override val expectationsFolder = "/expected_results/security_constraints/" | ||
|
||
val fixtures = new File("compiler/src/test/resources/examples").listFiles | ||
|
||
describe("Swagger ApiCall Converter with security constraints") { | ||
fixtures.filter(_.getName.endsWith(".yaml")).foreach { file => | ||
testSecurityConverter(file) | ||
} | ||
} | ||
|
||
def testSecurityConverter(file: File): Unit = { | ||
it(s"should convert security constraints in ${file.getName}") { | ||
val (base, model) = StrictYamlParser.parse(file) | ||
val ast = ModelConverter.fromModel(base, model, Option(file)) | ||
val fullResult = ast.calls.filter(_.security.nonEmpty).flatMap(_.security).distinct.mkString("\n") | ||
val expected = asInFile(file, "types") | ||
if (expected.isEmpty && fullResult.trim.nonEmpty) | ||
dump(fullResult, file, "types") | ||
clean(fullResult) mustBe clean(expected) | ||
} | ||
} | ||
|
||
def clean(str: String) = str.split("\n").map(_.trim).mkString("\n") | ||
} |