1818import  sys 
1919import  os 
2020import  ssl 
21+ import  socket 
2122
2223sys .path .append (".." )
2324
@@ -43,72 +44,70 @@ def with_remote():
4344    # 
4445    # which starts it in "console" mode with an empty in-memory TinkerGraph ready to go bound to a 
4546    # variable named "g" as referenced in the following line. 
47+     # if there is a port placeholder in the env var then we are running with docker so set appropriate port  
4648    server_url  =  os .getenv ('GREMLIN_SERVER_URL' , 'ws://localhost:8182/gremlin' ).format (45940 )
4749    rc  =  DriverRemoteConnection (server_url , 'g' )
4850    g  =  traversal ().with_remote (rc )
4951
50-     # drop existing vertices 
51-     g .V ().drop ().iterate ()
52- 
5352    # simple query to verify connection 
54-     v  =  g .add_v ().iterate ()
55-     count  =  g .V ().count ().next ()
53+     v  =  g .add_v ('py-conn-ex' ).iterate ()
54+     count  =  g .V ().has_label ( 'py-conn-ex' ). count ().next ()
5655    print ("Vertex count: "  +  str (count ))
5756
57+     # clean added data 
58+     g .V ().has_label ('py-conn-ex' ).drop ().iterate ()
5859    # cleanup 
5960    rc .close ()
6061
6162
6263# connecting with plain text authentication 
6364def  with_auth ():
65+     # if there is a port placeholder in the env var then we are running with docker so set appropriate port  
6466    server_url  =  os .getenv ('GREMLIN_SERVER_BASIC_AUTH_URL' , 'ws://localhost:8182/gremlin' ).format (45941 )
65-     # turn off certificate verification for testing purposes only 
66-     ssl_opts  =  ssl .SSLContext (ssl .PROTOCOL_TLS_CLIENT )
67-     ssl_opts .check_hostname  =  False 
68-     ssl_opts .verify_mode  =  ssl .CERT_NONE 
69-     rc  =  DriverRemoteConnection (server_url , 'g' , username = 'stephen' , password = 'password' ,
70-                                 transport_factory = lambda : AiohttpTransport (ssl_options = ssl_opts ))
67+     
68+     # disable SSL certificate verification for remote hosts in test environments 
69+     if  'localhost'  not  in server_url :
70+         ssl_opts  =  ssl .SSLContext (ssl .PROTOCOL_TLS_CLIENT )
71+         ssl_opts .check_hostname  =  False 
72+         ssl_opts .verify_mode  =  ssl .CERT_NONE 
73+         rc  =  DriverRemoteConnection (server_url , 'g' , username = 'stephen' , password = 'password' ,
74+                                     transport_factory = lambda : AiohttpTransport (ssl_options = ssl_opts ))
75+     else :
76+         rc  =  DriverRemoteConnection (server_url , 'g' , username = 'stephen' , password = 'password' )
77+     
7178    g  =  traversal ().with_remote (rc )
7279
73-     # drop existing vertices 
74-     g .V ().drop ().iterate ()
75- 
76-     v  =  g .add_v ().iterate ()
77-     count  =  g .V ().count ().next ()
80+     v  =  g .add_v ('py-conn-ex' ).iterate ()
81+     count  =  g .V ().has_label ('py-conn-ex' ).count ().next ()
7882    print ("Vertex count: "  +  str (count ))
7983
8084    # clean added data 
81-     g .V ().drop ().iterate ()
85+     g .V ().has_label ( 'py-conn-ex' ). drop ().iterate ()
8286    rc .close ()
8387
8488
8589# connecting with Kerberos SASL authentication 
8690def  with_kerberos ():
91+     # if there is a port placeholder in the env var then we are running with docker so set appropriate port  
8792    server_url  =  os .getenv ('GREMLIN_SERVER_URL' , 'ws://localhost:8182/gremlin' ).format (45942 )
88-     kerberos_hostname  =  os .getenv ('KRB_HOSTNAME' , 'gremlin-server-test' )
93+     kerberos_hostname  =  os .getenv ('KRB_HOSTNAME' , socket . gethostname () )
8994    kerberized_service  =  f'test-service@{ kerberos_hostname }  
9095
91-     try :
92-         rc  =  DriverRemoteConnection (server_url , 'g' , kerberized_service = kerberized_service )
93-         g  =  traversal ().with_remote (rc )
94- 
95-         # drop existing vertices 
96-         g .V ().drop ().iterate ()
96+     rc  =  DriverRemoteConnection (server_url , 'g' , kerberized_service = kerberized_service )
97+     g  =  traversal ().with_remote (rc )
9798
98-          v  =  g .add_v ().iterate ()
99-          count  =  g .V ().count ().next ()
100-          print ("Vertex count: "  +  str (count ))
99+     v  =  g .add_v ('py-conn-ex' ).iterate ()
100+     count  =  g .V (). has_label ( 'py-conn-ex' ).count ().next ()
101+     print ("Vertex count: "  +  str (count ))
101102
102-         # clean added data 
103-         g .V ().drop ().iterate ()
104-         rc .close ()
105-     except  Exception  as  e :
106-         print (f"Kerberos authentication failed (expected in test environment): { e }  )
107-         # This is expected to fail in CI without proper Kerberos setup 
103+     # clean added data 
104+     g .V ().has_label ('py-conn-ex' ).drop ().iterate ()
105+     rc .close ()
108106
109107
110108# connecting with customized configurations 
111109def  with_configs ():
110+     # if there is a port placeholder in the env var then we are running with docker so set appropriate port  
112111    server_url  =  os .getenv ('GREMLIN_SERVER_URL' , 'ws://localhost:8182/gremlin' ).format (45940 )
113112    rc  =  DriverRemoteConnection (
114113        server_url , 'g' ,
@@ -119,12 +118,12 @@ def with_configs():
119118    )
120119    g  =  traversal ().with_remote (rc )
121120
122-     v  =  g .add_v ().iterate ()
123-     count  =  g .V ().count ().next ()
121+     v  =  g .add_v ('py-conn-ex' ).iterate ()
122+     count  =  g .V ().has_label ( 'py-conn-ex' ). count ().next ()
124123    print ("Vertex count: "  +  str (count ))
125124
126125    # clean added data 
127-     g .V ().drop ().iterate ()
126+     g .V ().has_label ( 'py-conn-ex' ). drop ().iterate ()
128127
129128    rc .close ()
130129
0 commit comments