Skip to content

Commit

Permalink
Updated mist default config values in the payload
Browse files Browse the repository at this point in the history
Updated default config values in the payload
  • Loading branch information
jamesgreen-moj committed Dec 20, 2023
1 parent e11dcbe commit bc8f8e1
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 71 deletions.
85 changes: 85 additions & 0 deletions src/juniper.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,97 @@ def build_payload(
"bounce": "1-4 Hours",
"engaged": "7-10 Hours",
"stationed": "14-24 Hours"
},
"hours": {
"sun": None,
"mon": None,
"tue": None,
"wed": None,
"thu": None,
"fri": None,
"sat": None
}
},
"analytic": {
"enabled": True
},

"rtsa": {
"enabled": False,
"track_asset": False,
"app_waking": False
},
"led": {
"enabled": True,
"brightness": 255
},
"wifi": {
"enabled": True,
"locate_unconnected": True,
"mesh_enabled": True,
"mesh_allow_dfs": True
},

"switch_mgmt": {
"use_mxedge_proxy": False,
"mxedge_proxy_port": "2222"
},

"wootcloud": None,
"skyatp": {
"enabled": None,
"send_ip_mac_mapping": None
},

"mgmt": {
"use_wxtunnel": False
},

"config_auto_revert": True,
"status_portal": {
"enabled": False,
"hostnames": [
""
]
},
"uplink_port_config": {
"keep_wlans_up_if_down": True
},
"ssh_keys": [],
"wids": {},
"mxtunnel": {
"enabled": False
},
"occupancy": {
"min_duration": None,
"clients_enabled": False,
"sdkclients_enabled": False,
"assets_enabled": False,
"unconnected_clients_enabled": False
},
"public_zone_occupancy": {
"enabled": False,
"client_density_enabled": False,
"rssi_zones_enabled": False
},
"zone_occupancy_alert": {
"enabled": False,
"threshold": 5,
"email_notifiers": []
},
"gateway_mgmt": {
"app_usage": False,
"security_log_source_interface": "",
"auto_signature_update": {
"enable": True,
"time_of_day": "02:00",
"day_of_week": ""
}
},
"tunterm_monitoring": [],
"tunterm_monitoring_disabled": True,
"ssr": {},

"vars": {
"site_specific_radius_wired_nacs_secret": d.get('Wired NACS Radius Key', ''),
"site_specific_radius_govwifi_secret": d.get('GovWifi Radius Key', ''),
Expand Down
90 changes: 19 additions & 71 deletions test/test_juniper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import unittest
from unittest.mock import patch, MagicMock
from src.juniper import juniper_script, Admin, check_if_we_need_to_append_gov_wifi_or_moj_wifi_site_groups, warn_if_using_org_id_production, plan_of_action
from src.juniper import juniper_script, Admin, check_if_we_need_to_append_gov_wifi_or_moj_wifi_site_groups, \
warn_if_using_org_id_production, plan_of_action
from io import StringIO
from datetime import datetime
import os
Expand Down Expand Up @@ -37,70 +38,12 @@ def test_juniper_script(self, mock_put, mock_post, mock_successful_login, api_to
)

# Assertions
mock_post.assert_called_once_with('/api/v1/orgs/your_org_id/sites', {
'name': 'TestSite',
'address': '123 Main St',
'latlng': {'lat': 1.23, 'lng': 4.56},
'country_code': 'US',
'rftemplate_id': '8542a5fa-51e4-41be-83b9-acb416362cc0',
'networktemplate_id': '46b87163-abd2-4b08-a67f-1ccecfcfd061',
'timezone': 'UTC',
'sitegroup_ids': []
})

mock_put.assert_called_once_with('/api/v1/sites/123/setting', {

"auto_upgrade": {
"enabled": True,
"version": "custom",
"time_of_day": "02:00",
"custom_versions": {
"AP45": "0.12.27139",
"AP32": "0.12.27139"
},
"day_of_week": ""
},

"rogue": {
"min_rssi": -80,
"min_duration": 20,
"enabled": True,
"honeypot_enabled": True,
"whitelisted_bssids": [
""
],
"whitelisted_ssids": [
"GovWifi"
]
},

"persist_config_on_device": True,

"engagement": {
"dwell_tags": {
"passerby": "1-300",
"bounce": "3600-14400",
"engaged": "25200-36000",
"stationed": "50400-86400"
},
"dwell_tag_names": {
"passerby": "Below 5 Min (Passerby)",
"bounce": "1-4 Hours",
"engaged": "7-10 Hours",
"stationed": "14-24 Hours"
}
},
"analytic": {
"enabled": True
},

'vars': {
'site_specific_radius_wired_nacs_secret': 'key1',
'site_specific_radius_govwifi_secret': 'key2',
'address': '123 Main St',
'site_name': 'TestSite'
}
})
mock_post.assert_called_once_with('/api/v1/orgs/your_org_id/sites',
{'name': 'TestSite', 'address': '123 Main St',
'latlng': {'lat': 1.23, 'lng': 4.56}, 'country_code': 'US',
'rftemplate_id': '8542a5fa-51e4-41be-83b9-acb416362cc0',
'networktemplate_id': '46b87163-abd2-4b08-a67f-1ccecfcfd061',
'timezone': 'UTC', 'sitegroup_ids': []})

def test_juniper_script_missing_site_group_ids(self):
with self.assertRaises(ValueError) as cm:
Expand All @@ -116,15 +59,16 @@ def test_juniper_script_missing_rf_template_id(self):
org_id='your_org_id',
mist_login_method='token',
site_group_ids={
'moj_wifi': '0b33c61d-8f51-4757-a14d-29263421a904',
'gov_wifi': '70f3e8af-85c3-484d-8d90-93e28b911efb'},
'moj_wifi': '0b33c61d-8f51-4757-a14d-29263421a904',
'gov_wifi': '70f3e8af-85c3-484d-8d90-93e28b911efb'},
network_template_id='46b87163-abd2-4b08-a67f-1ccecfcfd061'
)

self.assertEqual(str(cm.exception), 'Must define rf_template_id')

@patch('builtins.input', return_value='y')
def test_given_production_org_id_when_user_prompted_for_input_and_user_inputs_y_then_continue_to_run(self, user_input):
def test_given_production_org_id_when_user_prompted_for_input_and_user_inputs_y_then_continue_to_run(self,
user_input):
production_org_id = '3e824dd6-6b37-4cc7-90bb-97d744e91175'
result = warn_if_using_org_id_production(production_org_id)
self.assertEqual(result, 'Continuing_with_run')
Expand All @@ -136,7 +80,8 @@ def test_given_production_org_id_when_user_prompted_for_input_and_user_inputs_n_
warn_if_using_org_id_production(production_org_id)

@patch('builtins.input', return_value='invalid')
def test_given_production_org_id_when_user_prompted_for_input_and_user_inputs_invalid_then_raise_error(self, user_input):
def test_given_production_org_id_when_user_prompted_for_input_and_user_inputs_invalid_then_raise_error(self,
user_input):
production_org_id = '3e824dd6-6b37-4cc7-90bb-97d744e91175'
with self.assertRaises(ValueError) as cm:
warn_if_using_org_id_production(production_org_id)
Expand Down Expand Up @@ -199,7 +144,8 @@ def test_login_successfully_via_username_and_password(self, mock_post, input_mfa
@patch('getpass.getpass', return_value='password')
@patch('builtins.input', return_value='123456')
@patch('src.juniper.requests.Session.post', return_value=MagicMock(status_code=400))
def test_given_valid_username_and_password_when_post_to_api_and_non_200_status_code_received_then_raise_error_to_user(self, mock_post, mfa_input, password_input):
def test_given_valid_username_and_password_when_post_to_api_and_non_200_status_code_received_then_raise_error_to_user(
self, mock_post, mfa_input, password_input):
with self.assertRaises(ValueError) as context:
admin = Admin(username='[email protected]',
mist_login_method='credentials')
Expand All @@ -219,7 +165,9 @@ def test_given_valid_username_and_password_when_post_to_api_and_non_200_status_c

@patch('getpass.getpass', return_value='test_token')
@patch('src.juniper.requests.Session')
def test_given_valid_api_token_when_post_to_api_and_non_200_status_code_received_then_raise_error_to_user(self, mock_session, api_token):
def test_given_valid_api_token_when_post_to_api_and_non_200_status_code_received_then_raise_error_to_user(self,
mock_session,
api_token):
mock_get = mock_session.return_value.get
mock_get.return_value = MagicMock(status_code=400)

Expand Down

0 comments on commit bc8f8e1

Please sign in to comment.