Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
squito committed Dec 18, 2018
1 parent 7b2d223 commit e83b160
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private[spark] object PythonGatewayServer extends Logging {
builder.authToken(secret)
} else {
assert(sys.env.getOrElse("SPARK_TESTING", "0") == "1",
"Creating insecure java gateways only allowed for testing")
"Creating insecure Java gateways only allowed for testing")
}
val gatewayServer: GatewayServer = builder.build()

Expand Down
4 changes: 2 additions & 2 deletions python/pyspark/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@ def __init__(self, master=None, appName=None, sparkHome=None, pyFiles=None,
if gateway is not None and gateway.gateway_parameters.auth_token is None:
if conf and conf.get("spark.python.allowInsecurePy4j", "false") == "true":
warnings.warn(
"You are passing in an insecure py4j gateway. This "
"You are passing in an insecure Py4j gateway. This "
"presents a security risk, and will be completely forbidden in Spark 3.0")
else:
raise Exception(
"You are trying to pass an insecure py4j gateway to spark. This"
"You are trying to pass an insecure Py4j gateway to Spark. This"
" presents a security risk. If you are sure you understand and accept this"
" risk, you can add the conf 'spark.python.allowInsecurePy4j=true', but"
" note this option will be removed in Spark 3.0")
Expand Down
4 changes: 2 additions & 2 deletions python/pyspark/java_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def launch_gateway(conf=None):
"""
launch jvm gateway
:param conf: spark configuration passed to spark-submit
:return:
:return: a JVM gateway
"""
return _launch_gateway(conf)

Expand All @@ -50,7 +50,7 @@ def _launch_gateway(conf=None, insecure=False):
"""
launch jvm gateway
:param conf: spark configuration passed to spark-submit
:return:
:return: a JVM gateway
"""
if insecure and not os.environ.get("SPARK_TESTING", "0") == "1":
raise Exception("creating insecure gateways is only for testing")
Expand Down
14 changes: 4 additions & 10 deletions python/pyspark/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2388,9 +2388,9 @@ def test_forbid_insecure_gateway(self):
gateway = _launch_gateway(insecure=True)
with self.assertRaises(Exception) as context:
SparkContext(gateway=gateway)
self.assertIn("insecure py4j gateway", context.exception.message)
self.assertIn("spark.python.allowInsecurePy4j", context.exception.message)
self.assertIn("removed in Spark 3.0", context.exception.message)
self.assertIn("insecure Py4j gateway", str(context.exception))
self.assertIn("spark.python.allowInsecurePy4j", str(context.exception))
self.assertIn("removed in Spark 3.0", str(context.exception))

def test_allow_insecure_gateway_with_conf(self):
with SparkContext._lock:
Expand All @@ -2399,18 +2399,12 @@ def test_allow_insecure_gateway_with_conf(self):
gateway = _launch_gateway(insecure=True)
conf = SparkConf()
conf.set("spark.python.allowInsecurePy4j", "true")
print("entering allow insecure test")
with SparkContext(conf=conf, gateway=gateway) as sc:
print("sc created, about to create accum")
a = sc.accumulator(1)
rdd = sc.parallelize([1, 2, 3])

def f(x):
a.add(x)

rdd.foreach(f)
rdd.foreach(lambda x: a.add(x))
self.assertEqual(7, a.value)
print("exiting allow insecure test")


class ConfTests(unittest.TestCase):
Expand Down

0 comments on commit e83b160

Please sign in to comment.