예제 #1
0
        static ApisJson GetExceptedApisJsonForServerPathWithNoSubDirectories()
        {
            var exceptedApisJsonForServerNoSecurity = new ApisJson
            {
                Name                 = EnvironmentVariables.PublicWebServerUri,
                Created              = DateTime.Today.Date,
                Modified             = DateTime.Today.Date,
                Description          = "",
                Url                  = EnvironmentVariables.PublicWebServerUri + "Acceptance Testing Resources/Execution Engine/apis.json",
                SpecificationVersion = "0.15",
                Apis                 = new List <SingleApi>()
            };

            var singleApi2 = new SingleApi
            {
                Name        = "Execution Engine Test",
                Description = "",
                BaseUrl     = EnvironmentVariables.PublicWebServerUri + "secure/Acceptance Testing Resources/Execution Engine/Execution Engine Test.json",
                Properties  = new List <PropertyApi>(),
                HumanUrl    = "https://warewolf.io",
                Image       = "https://warewolf.io/images/logo.png",
                Version     = "1.0",
                Tags        = new List <string>()
            };
            var swagger2 = new PropertyApi
            {
                Type  = "Swagger",
                Value = EnvironmentVariables.PublicWebServerUri + "secure/Acceptance Testing Resources/Execution Engine/Execution Engine Test.api"
            };

            singleApi2.Properties.Add(swagger2);

            exceptedApisJsonForServerNoSecurity.Apis.Add(singleApi2);
            return(exceptedApisJsonForServerNoSecurity);
        }
예제 #2
0
        public void ApisJsonBuilder_Maintainers_Equals()
        {
            var apiJson = new ApisJson
            {
                Maintainers = new List <MaintainerApi>()
                {
                    new MaintainerApi()
                    {
                        Fn       = "Ashley Lewis",
                        Email    = "*****@*****.**",
                        Url      = "https://warewolf.io",
                        Org      = "https://dev2.co.za",
                        Adr      = "Bellevue, Kloof",
                        Tel      = "9139",
                        XTwitter = "@warewolf",
                        XGithub  = "Warewolf-ESB/Warewolf",
                        Photo    = "https://warewolf.io/images/logo.png",
                        VCard    = "39A03A58-978F-4CFB-B1D1-3EFA6C55E380"
                    }
                }
            };
            var differentApiJson = new ApisJson
            {
                Maintainers = new List <MaintainerApi>()
                {
                    new MaintainerApi()
                    {
                        Fn    = "A Totally Different Ashley Lewis",
                        Email = "*****@*****.**"
                    }
                }
            };

            Assert.IsFalse(differentApiJson.Maintainers == apiJson.Maintainers, "ApisJson object cannot compare Maintainers.");
        }
예제 #3
0
        static ApisJson GetExceptedApisJsonForServerNoSecurity()
        {
            var exceptedApisJsonForServerNoSecurity = new ApisJson
            {
                Name                 = EnvironmentVariables.PublicWebServerUri,
                Created              = DateTime.Today.Date,
                Modified             = DateTime.Today.Date,
                Description          = "",
                Url                  = EnvironmentVariables.PublicWebServerUri + "apis.json",
                SpecificationVersion = "0.15",
                Apis                 = new List <SingleApi>()
            };
            var singleApi1 = new SingleApi
            {
                Name        = "Hello World",
                Description = "",
                BaseUrl     = EnvironmentVariables.PublicWebServerUri + "secure/Hello World.json",
                Properties  = new List <PropertyApi>()
            };
            var swagger1 = new PropertyApi
            {
                Type  = "Swagger",
                Value = EnvironmentVariables.PublicWebServerUri + "secure/Hello World.api"
            };

            singleApi1.Properties.Add(swagger1);

            var singleApi2 = new SingleApi
            {
                Name        = "Execution Engine Test",
                Description = "",
                BaseUrl     = EnvironmentVariables.PublicWebServerUri + "secure/Acceptance Testing Resources/Execution Engine/Execution Engine Test.json",
                Properties  = new List <PropertyApi>()
            };
            var swagger2 = new PropertyApi
            {
                Type  = "Swagger",
                Value = EnvironmentVariables.PublicWebServerUri + "secure/Acceptance Testing Resources/Execution Engine/Execution Engine Test.api"
            };

            singleApi2.Properties.Add(swagger2);
            var singleApi3 = new SingleApi
            {
                Name        = "9139Local",
                Description = "",
                BaseUrl     = EnvironmentVariables.PublicWebServerUri + "secure/Acceptance Testing Resources/9139Local.json",
                Properties  = new List <PropertyApi>()
            };
            var swagger3 = new PropertyApi
            {
                Type  = "Swagger",
                Value = EnvironmentVariables.PublicWebServerUri + "secure/Acceptance Testing Resources/9139Local.api"
            };

            singleApi3.Properties.Add(swagger3);
            exceptedApisJsonForServerNoSecurity.Apis.Add(singleApi1);
            exceptedApisJsonForServerNoSecurity.Apis.Add(singleApi2);
            exceptedApisJsonForServerNoSecurity.Apis.Add(singleApi3);
            return(exceptedApisJsonForServerNoSecurity);
        }
예제 #4
0
        public void ParseAPIsJsonDocumentMinimal()
        {
            var stream = this.GetType().Assembly.GetManifestResourceStream(this.GetType(), "apis.json");

            var rootMap = new VocabTerm <ApisJson>(null);

            rootMap.MapProperty <string>("name", (s, o) => s.Name = o);
            rootMap.MapProperty <string>("url", (s, o) => s.Url   = new Uri(o));

            var apiMap = new VocabTerm <ApisJsonApi>("apis");

            apiMap.MapProperty <string>("name", (s, o) => s.Name        = o);
            apiMap.MapProperty <string>("description", (s, o) => s.Name = o);
            apiMap.MapProperty <string>("baseUrl", (s, o) => s.BaseUrl  = new Uri(o));

            rootMap.MapObject <ApisJsonApi>(apiMap, (s) =>
            {
                if (s.Apis == null)
                {
                    s.Apis = new List <ApisJsonApi>();
                }
                var api = new ApisJsonApi();
                s.Apis.Add(api);
                return(api);
            });

            var apis = new ApisJson();

            JsonStreamingParser.ParseStream(stream, apis, rootMap);

            Assert.Equal("API Evangelist", apis.Name);
            Assert.Equal(2, apis.Apis.Count());
        }
예제 #5
0
        public void ApisJsonBuilder_Include_Equals()
        {
            var apiJson = new ApisJson
            {
                Include = new List <IncludeApi>()
                {
                    new IncludeApi()
                    {
                        Name = "Included Api",
                        Url  = "Included Url"
                    }
                }
            };
            var differentApiJson = new ApisJson
            {
                Include = new List <IncludeApi>()
                {
                    new IncludeApi()
                    {
                        Name = "Different Included Api",
                        Url  = "Different Included Url"
                    }
                }
            };

            Assert.IsFalse(differentApiJson.Include == apiJson.Include, "ApisJson object cannot compare Included Apis.");
        }
예제 #6
0
        public void ApisJsonBuilder_GetHashCode()
        {
            var apiJson = new ApisJson
            {
                Name                 = EnvironmentVariables.PublicWebServerUri,
                Description          = "",
                SpecificationVersion = "0.15",
                Apis                 = new List <SingleApi>()
            };

            Assert.IsInstanceOfType(apiJson.GetHashCode(), typeof(int), "ApisJson object did not hash.");
        }
예제 #7
0
        public ApisJson BuildForPath(string path, bool isPublic)
        {
            var apiJson = new ApisJson
            {
                Name                 = EnvironmentVariables.PublicWebServerUri,
                Description          = "",
                Created              = DateTime.Today.Date,
                Modified             = DateTime.Today.Date,
                SpecificationVersion = "0.15",
                Apis                 = new List <SingleApi>()
            };
            IList <IResource> resourceList;

            if (string.IsNullOrEmpty(path))
            {
                apiJson.Url  = EnvironmentVariables.PublicWebServerUri + "apis.json";
                resourceList = ResourceCatalog.GetResourceList(GlobalConstants.ServerWorkspaceID).Where(resource => resource.ResourceType == "WorkflowService").ToList();
            }
            else
            {
                var webPath    = path.Replace("\\", "/");
                var searchPath = path.Replace("/", "\\");
                apiJson.Url  = EnvironmentVariables.PublicWebServerUri + webPath + "/apis.json";
                resourceList = ResourceCatalog.GetResourceList(GlobalConstants.ServerWorkspaceID).Where(resource => resource.GetResourcePath(GlobalConstants.ServerWorkspaceID).Contains(searchPath) && resource.ResourceType == "WorkflowService").ToList();
            }
            foreach (var resource in resourceList)
            {
                if (isPublic)
                {
                    var publicCanExecute = AuthorizationService.IsAuthorized(GlobalConstants.GenericPrincipal, AuthorizationContext.Execute, resource);
                    var publicCanView    = AuthorizationService.IsAuthorized(GlobalConstants.GenericPrincipal, AuthorizationContext.View, resource);
                    if (publicCanExecute && publicCanView)
                    {
                        apiJson.Apis.Add(CreateSingleApiForResource(resource, true));
                    }
                }
                else
                {
                    var canExecute = AuthorizationService.IsAuthorized(AuthorizationContext.Execute, resource);
                    var canView    = AuthorizationService.IsAuthorized(AuthorizationContext.View, resource);
                    if (canView && canExecute)
                    {
                        apiJson.Apis.Add(CreateSingleApiForResource(resource, false));
                    }
                }
            }
            return(apiJson);
        }
 public ApisJson BuildForPath(string path, bool isPublic)
 {
     var apiJson = new ApisJson
     {
         Name = EnvironmentVariables.PublicWebServerUri,
         Description = "",
         Created = DateTime.Today.Date,
         Modified = DateTime.Today.Date,
         SpecificationVersion = "0.15",
         Apis = new List<SingleApi>()
     };
     IList<IResource> resourceList;
     if(string.IsNullOrEmpty(path))
     {
         apiJson.Url = EnvironmentVariables.PublicWebServerUri + "apis.json";
         resourceList = ResourceCatalog.GetResourceList(GlobalConstants.ServerWorkspaceID).Where(resource => resource.ResourceType==ResourceType.WorkflowService).ToList();
     }
     else
     {
         var webPath = path.Replace("\\", "/");
         var searchPath = path.Replace("/", "\\");
         apiJson.Url = EnvironmentVariables.PublicWebServerUri + webPath + "/apis.json";
         resourceList = ResourceCatalog.GetResourceList(GlobalConstants.ServerWorkspaceID).Where(resource => resource.ResourcePath.Contains(searchPath) && resource.ResourceType == ResourceType.WorkflowService).ToList();
     }
     foreach(var resource in resourceList)
     {
         if (isPublic)
         {
             var publicCanExecute = AuthorizationService.IsAuthorized(GlobalConstants.GenericPrincipal, AuthorizationContext.Execute, resource.ResourceID.ToString());
             var publicCanView = AuthorizationService.IsAuthorized(GlobalConstants.GenericPrincipal, AuthorizationContext.View, resource.ResourceID.ToString());
             if (publicCanExecute && publicCanView)
             {
                 apiJson.Apis.Add(CreateSingleApiForResource(resource, true));
             }
         }
         else
         {
             var canExecute = AuthorizationService.IsAuthorized(AuthorizationContext.Execute, resource.ResourceID.ToString());
             var canView = AuthorizationService.IsAuthorized(AuthorizationContext.View, resource.ResourceID.ToString());
             if (canView && canExecute)
             {
                 apiJson.Apis.Add(CreateSingleApiForResource(resource, false));
             }
         }
        
     }
     return apiJson;
 }
예제 #9
0
        private static ApisJson GetInstance(List <SingleApi> singleApis, List <IncludeApi> includeApis, List <MaintainerApi> maintainerApis)
        {
            var p = new ApisJson
            {
                Apis                 = singleApis,
                Created              = new DateTime(10000000),
                Description          = "Some description",
                Image                = "Some image",
                Include              = includeApis,
                Maintainers          = maintainerApis,
                Modified             = new DateTime(20000000),
                Name                 = "Some Name",
                SpecificationVersion = "spec version",
                Tags                 = new List <string> {
                    "s1", "s2"
                },
                Url = "some url",
            };

            return(p);
        }
예제 #10
0
        public void ParseAPIsJsonDocument()
        {
            var stream = this.GetType().Assembly.GetManifestResourceStream(this.GetType(), "apis.json");

            var vocab = ApisJsonVocab.Create();

            //new VocabTerm<ApisJson>(null);

            //vocab.MapProperty<string>("name", (s, o) => { s.Name = o; });
            //vocab.MapProperty<string>("url", (s, o) => { s.Url = new Uri(o); });
            //vocab.MapProperty<string>("image", (s, o) => { s.Image = new Uri(o); });
            //vocab.MapProperty<string>("modified", (s, o) => { s.Modified = DateTime.Parse(o); });
            //vocab.MapProperty<string>("created", (s, o) => { s.Created = DateTime.Parse(o); });
            //vocab.MapProperty<string>("tags", (s, o) => {
            //    if (s.Tags == null) s.Tags = new List<string>();
            //    s.Tags.Add(o); });
            //vocab.MapProperty<string>("specificationVersion", (s, o) => { s.SpecificationVersion = o; });


            //var apivocab = new VocabTerm<ApisJsonApi>("apis");
            //apivocab.MapProperty<string>("name", (s, o) => { s.Name = o; });
            //apivocab.MapProperty<string>("description", (s, o) => { s.Name = o; });
            //apivocab.MapProperty<string>("humanUrl", (s, o) => { s.HumanUrl = new Uri(o); });
            //apivocab.MapProperty<string>("baseUrl", (s, o) => { s.BaseUrl = new Uri(o); });
            //apivocab.MapProperty<string>("image", (s, o) => { s.Image = new Uri(o); });
            //apivocab.MapProperty<string>("tags", (s, o) => {
            //    if (s.Tags == null) s.Tags = new List<string>();
            //    s.Tags.Add(o);
            //});

            //vocab.MapObject<ApisJsonApi>(apivocab, (s) =>
            //{
            //    if (s.Apis == null)
            //    {
            //        s.Apis = new List<ApisJsonApi>();
            //    }
            //    var api = new ApisJsonApi();
            //    s.Apis.Add(api);
            //    return api;
            //});

            //var propertyTerm = new VocabTerm<ApisJsonProperty>("properties");
            //propertyTerm.MapProperty<string>("url", (s, o) => { s.Url = new Uri(o);});
            //propertyTerm.MapProperty<string>("type", (s, o) => { s.Type = o;});


            //apivocab.MapObject<ApisJsonProperty>(propertyTerm, (s) =>
            //{
            //    if (s.Properties == null)
            //    {
            //        s.Properties = new List<ApisJsonProperty>();
            //    }
            //    var property = new ApisJsonProperty();
            //    s.Properties.Add(property);
            //    return property;
            //});


            var apis = new ApisJson();

            JsonStreamingParser.ParseStream(stream, apis, vocab);

            Assert.Equal("API Evangelist", apis.Name);
            Assert.Equal(2, apis.Apis.Count());
        }
 static ApisJson GetExceptedApisJsonForServerPathWithNoSubDirectories()
 {
     var exceptedApisJsonForServerNoSecurity = new ApisJson
     {
         Name = EnvironmentVariables.PublicWebServerUri,
         Created = DateTime.Today.Date,
         Modified = DateTime.Today.Date,
         Description = "",
         Url = EnvironmentVariables.PublicWebServerUri + "Acceptance Testing Resources/Execution Engine/apis.json",
         SpecificationVersion = "0.15",
         Apis = new List<SingleApi>()
     };
     
     var singleApi2 = new SingleApi
     {
         Name = "Execution Engine Test",
         Description = "",
         BaseUrl = EnvironmentVariables.PublicWebServerUri + "secure/Acceptance Testing Resources/Execution Engine/Execution Engine Test.json",
         Properties = new List<PropertyApi>()
     };
     var swagger2 = new PropertyApi
     {
         Type = "Swagger",
         Value = EnvironmentVariables.PublicWebServerUri + "secure/Acceptance Testing Resources/Execution Engine/Execution Engine Test.api"
     };
     singleApi2.Properties.Add(swagger2);
     
     exceptedApisJsonForServerNoSecurity.Apis.Add(singleApi2);
     return exceptedApisJsonForServerNoSecurity;
 }
 static ApisJson GetExceptedApisJsonForServerSecurity()
 {
     var exceptedApisJsonForServerNoSecurity = new ApisJson
     {
         Name = EnvironmentVariables.PublicWebServerUri,
         Created = DateTime.Today.Date,
         Modified = DateTime.Today.Date,
         Description = "",
         Url = EnvironmentVariables.PublicWebServerUri + "apis.json",
         SpecificationVersion = "0.15",
         Apis = new List<SingleApi>()
     };
     var singleApi1 = new SingleApi
     {
         Name = "Hello World",
         Description = "",
         BaseUrl = EnvironmentVariables.PublicWebServerUri + "secure/Hello World.json",
         Properties = new List<PropertyApi>()
     };
     var swagger1 = new PropertyApi
     {
         Type = "Swagger",
         Value = EnvironmentVariables.PublicWebServerUri + "secure/Hello World.api"
     };
     singleApi1.Properties.Add(swagger1);
     
     var singleApi3 = new SingleApi
     {
         Name = "9139Local",
         Description = "",
         BaseUrl = EnvironmentVariables.PublicWebServerUri + "secure/Acceptance Testing Resources/9139Local.json",
         Properties = new List<PropertyApi>()
     };
     var swagger3 = new PropertyApi
     {
         Type = "Swagger",
         Value = EnvironmentVariables.PublicWebServerUri + "secure/Acceptance Testing Resources/9139Local.api"
     };
     singleApi3.Properties.Add(swagger3);
     exceptedApisJsonForServerNoSecurity.Apis.Add(singleApi1);
     exceptedApisJsonForServerNoSecurity.Apis.Add(singleApi3);
     return exceptedApisJsonForServerNoSecurity;
 }