Skip to content
This repository has been archived by the owner on Apr 10, 2019. It is now read-only.

Commit

Permalink
#3, test: Integration test for security constraints
Browse files Browse the repository at this point in the history
  • Loading branch information
slavaschmidt committed Mar 5, 2016
1 parent 642696a commit 213388a
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BasicConstraint(Basic(Some(HTTP Basic Authentication. Works over `HTTP` and `HTTPS`)))
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))
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))
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))
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))
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")
}

0 comments on commit 213388a

Please sign in to comment.