endpoints_services_test.cpp
Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 #include "endpoints_services_test.h"
00012 #include "services_registry_test.h"
00013 
00014 #include <src/server/endpoints_parameters.h>
00015 #include <opc/ua/protocol/session.h>
00016 #include <opc/ua/server/endpoints_services.h>
00017 #include <gmock/gmock.h>
00018 #include <gtest/gtest.h>
00019 
00020 
00021 using namespace testing;
00022 
00023 class EndpointsRegistry :public Test
00024 {
00025 protected:
00026   virtual void SetUp()
00027   {
00028     Addons = Common::CreateAddonsManager();
00029     OpcUa::Test::RegisterServicesRegistry(*Addons);
00030     OpcUa::Test::RegisterEndpointsServicesAddon(*Addons);
00031     Addons->Start();
00032   }
00033 
00034   virtual void TearDown()
00035   {
00036     Addons->Stop();
00037     Addons.reset();
00038   }
00039 
00040 protected:
00041   std::unique_ptr<Common::AddonsManager> Addons;
00042 };
00043 
00044 TEST_F(EndpointsRegistry, CanBeCreated)
00045 {
00046   OpcUa::Server::EndpointsRegistry::SharedPtr endpoints;
00047 
00048   ASSERT_NO_THROW(endpoints = Addons->GetAddon<OpcUa::Server::EndpointsRegistry>(OpcUa::Server::EndpointsRegistryAddonId));
00049   ASSERT_TRUE(static_cast<bool>(endpoints));
00050 }
00051 
00052 TEST_F(EndpointsRegistry, RegisterEndpoints)
00053 {
00054   OpcUa::EndpointDescription desc;
00055   desc.EndpointUrl = "url";
00056 
00057   OpcUa::Server::EndpointsRegistry::SharedPtr endpoints = Addons->GetAddon<OpcUa::Server::EndpointsRegistry>(OpcUa::Server::EndpointsRegistryAddonId);
00058   endpoints->AddEndpoints(std::vector<OpcUa::EndpointDescription>(1, desc));
00059 
00060   OpcUa::Server::ServicesRegistry::SharedPtr services = Addons->GetAddon<OpcUa::Server::ServicesRegistry>(OpcUa::Server::ServicesRegistryAddonId);
00061   OpcUa::Services::SharedPtr computer = services->GetServer();
00062   std::vector<OpcUa::EndpointDescription> descriptions;
00063   ASSERT_NO_THROW(descriptions = computer->Endpoints()->GetEndpoints(OpcUa::GetEndpointsParameters()));
00064   ASSERT_EQ(descriptions.size(), 1);
00065   ASSERT_EQ(descriptions[0].EndpointUrl, "url");
00066 }
00067 
00068 std::vector<Common::ParametersGroup> CreateTwoEndpointsParameters()
00069 {
00070   Common::ParametersGroup data;
00071   data.Name = "application";
00072   data.Parameters.push_back(Common::Parameter("discovery_profile", "DiscoveryProfileUri"));
00073   data.Parameters.push_back(Common::Parameter("uri", "ApplicationUri"));
00074   data.Parameters.push_back(Common::Parameter("product_uri", "ProductUri"));
00075   data.Parameters.push_back(Common::Parameter("gateway_server_uri", "GatewayServerUri"));
00076   data.Parameters.push_back(Common::Parameter("name", "ApplicationName"));
00077   data.Parameters.push_back(Common::Parameter("type", "ApplicationType"));
00078 
00079   Common::ParametersGroup endpoint("endpoint");
00080   endpoint.Parameters.push_back(Common::Parameter("url", "EndpointUrl"));
00081   endpoint.Parameters.push_back(Common::Parameter("security_level", "1"));
00082   endpoint.Parameters.push_back(Common::Parameter("security_mode", "3"));
00083   endpoint.Parameters.push_back(Common::Parameter("security_policy_uri", "SecurityPolicyUri"));
00084   endpoint.Parameters.push_back(Common::Parameter("transport_profile_uri", "TransportProfileUri"));
00085 
00086   Common::ParametersGroup tokenPolicy("user_token_policy");
00087   tokenPolicy.Parameters.push_back(Common::Parameter("issued_token_type", "IssuedTokenType"));
00088   tokenPolicy.Parameters.push_back(Common::Parameter("issuer_endpoint_url", "IssuerEndpointUrl"));
00089   tokenPolicy.Parameters.push_back(Common::Parameter("id", "PolicyId"));
00090   tokenPolicy.Parameters.push_back(Common::Parameter("uri", "SecurityPolicyUri"));
00091   tokenPolicy.Parameters.push_back(Common::Parameter("type", "user_name"));
00092 
00093   endpoint.Groups.push_back(tokenPolicy);
00094   data.Groups.push_back(endpoint);
00095 
00096   return std::vector<Common::ParametersGroup>{data, data};
00097 }
00098 
00099 std::vector<OpcUa::Server::ApplicationData> CreateTwoEndpointsConfiguration()
00100 {
00101   OpcUa::Server::ApplicationData data;
00102   data.Application.DiscoveryProfileUri = "DiscoveryProfileUri";
00103   data.Application.ApplicationUri = "ApplicationUri";
00104   data.Application.ProductUri = "ProductUri";
00105   data.Application.GatewayServerUri = "GatewayServerUri";
00106   data.Application.ApplicationName = OpcUa::LocalizedText("Name");
00107   data.Application.ApplicationType = OpcUa::ApplicationType::Client;
00108 
00109   OpcUa::EndpointDescription ed;
00110   ed.EndpointUrl = "EndpointUrl";
00111   ed.SecurityLevel = 1;
00112   ed.SecurityMode = OpcUa::MessageSecurityMode::SignAndEncrypt;
00113   ed.SecurityPolicyUri = "SecurityPolicyUri";
00114   ed.TransportProfileUri = "TransportProfileUri";
00115 
00116   OpcUa::UserTokenPolicy tokenPolicy; // By default ot os an anonimous token;
00117   tokenPolicy.IssuedTokenType = "IssuedTokenType";
00118   tokenPolicy.IssuerEndpointUrl = "IssuerEndpointUrl";
00119   tokenPolicy.PolicyId = "PolicyId";
00120   tokenPolicy.SecurityPolicyUri = "SecurityPolicyUri";
00121   tokenPolicy.TokenType = OpcUa::UserTokenType::UserName;
00122   ed.UserIdentityTokens.push_back(tokenPolicy);
00123 
00124   data.Endpoints = {ed};
00125 
00126   return std::vector<OpcUa::Server::ApplicationData>{data, data};
00127 }
00128 
00129 Common::Parameter FindParameter(const Common::ParametersGroup& group, const char* name)
00130 {
00131   auto paramIt = std::find_if(group.Parameters.begin(), group.Parameters.end(), [name](const Common::Parameter& param){
00132     return param.Name == name;
00133   });
00134 
00135   if (paramIt != group.Parameters.end())
00136   {
00137     return *paramIt;
00138   }
00139   return Common::Parameter();
00140 }
00141 
00142 // TEST(EndpointParameters, ConvertingFromAddonParameters)
00143 // {
00144 //   std::vector<Common::ParametersGroup> params = CreateTwoEndpointsParameters();
00145 //   bool debug = true;
00146 //   std::vector<OpcUa::Server::ApplicationData> apps = OpcUa::ParseEndpointsParameters(params, debug);
00147 //   ASSERT_EQ(apps.size(), 2);
00148 //   OpcUa::Server::ApplicationData app = apps[0];
00149 //   EXPECT_EQ(app.Application.DiscoveryProfileUri, "DiscoveryProfileUri");
00150 //   EXPECT_EQ(app.Application.ApplicationUri, "ApplicationUri");
00151 //   EXPECT_EQ(app.Application.ProductUri, "ProductUri");
00152 //   EXPECT_TRUE(app.Application.ApplicationName.Encoding & OpcUa::HAS_TEXT);
00153 //   EXPECT_EQ(app.Application.ApplicationName.Text, "ApplicationName");
00154 //   EXPECT_EQ(app.Application.ApplicationType, OpcUa::ApplicationType::Client);
00155 //   EXPECT_EQ(app.Application.GatewayServerUri, "GatewayServerUri");
00156 //
00157 //   ASSERT_EQ(app.Endpoints.size(), 1);
00158 //   OpcUa::EndpointDescription ed = app.Endpoints[0];
00159 //   EXPECT_EQ(ed.EndpointUrl, "EndpointUrl");
00160 //   EXPECT_EQ(ed.SecurityLevel, 1);
00161 //   EXPECT_EQ(ed.SecurityMode, OpcUa::MessageSecurityMode::SignAndEncrypt);
00162 //   EXPECT_EQ(ed.SecurityPolicyUri, "SecurityPolicyUri");
00163 //   //EXPECT_EQ(ed.ServerCertificate, std::vector{1,2,3,4,5});
00164 //   //EXPECT_EQ(ed.ServerDescription, "SecurityPolicyUri");
00165 //   EXPECT_EQ(ed.TransportProfileUri, "TransportProfileUri");
00166 //
00167 //   ASSERT_EQ(ed.UserIdentityTokens.size(), 1);
00168 //   OpcUa::UserTokenPolicy tokenPolicy = ed.UserIdentityTokens[0];
00169 //   EXPECT_EQ(tokenPolicy.IssuedTokenType, "IssuedTokenType");
00170 //   EXPECT_EQ(tokenPolicy.IssuerEndpointUrl, "IssuerEndpointUrl");
00171 //   EXPECT_EQ(tokenPolicy.PolicyId, "PolicyId");
00172 //   EXPECT_EQ(tokenPolicy.SecurityPolicyUri, "SecurityPolicyUri");
00173 //   EXPECT_EQ(tokenPolicy.TokenType, OpcUa::UserTokenType::UserName);
00174 // }
00175 
00176 // TEST(EndpointParameters, ConvertingToAddonParameters)
00177 // {
00178 //   const std::vector<OpcUa::Server::ApplicationData>& application = CreateTwoEndpointsConfiguration();
00179 //   bool debug = true;
00180 //   const std::vector<Common::ParametersGroup>& result = OpcUa::CreateCommonParameters(application, debug);
00181 //   ASSERT_EQ(result.size(), 2);
00182 //   const Common::ParametersGroup applicationGroup = result[0];
00183 //   EXPECT_EQ(applicationGroup.Name, "application");
00184 //   EXPECT_EQ(FindParameter(applicationGroup, "discovery_profile").Value, "DiscoveryProfileUri");
00185 //   EXPECT_EQ(FindParameter(applicationGroup, "product_uri").Value, "ProductUri");
00186 //   EXPECT_EQ(FindParameter(applicationGroup, "application_uri").Value, "ApplicationUri");
00187 //   EXPECT_EQ(FindParameter(applicationGroup, "application_name").Value, "ApplicationName");
00188 //   EXPECT_EQ(FindParameter(applicationGroup, "Application_type").Value, "client");
00189 //   EXPECT_EQ(FindParameter(applicationGroup, "gateway_server_uri").Value, "GatewayServerUri");
00190 //
00191 //   ASSERT_EQ(applicationGroup.Groups.size(), 1) << "Application group has no subgroups with endpoints";
00192 //   Common::ParametersGroup endpoint = applicationGroup.Groups[0];
00193 //   EXPECT_EQ(endpoint.Name, "endpoint");
00194 //   EXPECT_EQ(FindParameter(endpoint, "endpoint_url").Value, "EndpointUrl");
00195 //   EXPECT_EQ(FindParameter(endpoint, "security_level").Value, "1");
00196 //   EXPECT_EQ(FindParameter(endpoint, "security_mode").Value, "3");
00197 //   EXPECT_EQ(FindParameter(endpoint, "security_policy_uri").Value, "SecurityPolicyUri");
00198 //   //EXPECT_EQ(FindParameter(endpoint, "server_certificate").Value, "SecurityPolicyUri");
00199 //   EXPECT_EQ(FindParameter(endpoint, "transport_profile_uri").Value, "TransportProfileUri");
00200 //
00201 //   ASSERT_EQ(endpoint.Groups.size(), 1);
00202 //   Common::ParametersGroup tokenPolicy = endpoint.Groups[0];
00203 //   EXPECT_EQ(tokenPolicy.Name, "user_token_policy");
00204 //   EXPECT_EQ(FindParameter(tokenPolicy, "issued_token_type").Value, "IssuedTokenType");
00205 //   EXPECT_EQ(FindParameter(tokenPolicy, "issuer_endpoint_url").Value, "IssuerEndpointUrl");
00206 //   EXPECT_EQ(FindParameter(tokenPolicy, "id").Value, "PolicyId");
00207 //   EXPECT_EQ(FindParameter(tokenPolicy, "id").Value, "PolicyId");
00208 //   EXPECT_EQ(FindParameter(tokenPolicy, "uri").Value, "SecurityPolicyUri");
00209 //   EXPECT_EQ(FindParameter(tokenPolicy, "type").Value, "user_name");
00210 // }


ros_opcua_impl_freeopcua
Author(s): Denis Štogl
autogenerated on Sat Jun 8 2019 18:24:40