codecov-io: # [Codecov](https://codecov.io/gh/Azure/azure-cli/pull/2575?src=pr&el=h1) Report
> Merging [#2575](https://codecov.io/gh/Azure/azure-cli/pull/2575?src=pr&el=desc) into [master](https://codecov.io/gh/Azure/azure-cli/commit/3b6324d00353405e547723056bb324fe3667731c?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.


```diff
@@            Coverage Diff             @@
##           master    #2575      +/-   ##
==========================================
+ Coverage   72.32%   72.32%   +<.01%     
==========================================
  Files         363      363              
  Lines       19835    19838       +3     
  Branches     2923     2924       +1     
==========================================
+ Hits        14345    14348       +3     
  Misses       4582     4582              
  Partials      908      908
```


| [Impacted Files](https://codecov.io/gh/Azure/azure-cli/pull/2575?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/azure-cli-core/azure/cli/core/\_profile.py](https://codecov.io/gh/Azure/azure-cli/compare/3b6324d00353405e547723056bb324fe3667731c...3eb700a6096e68ea881880a9e976c43d060eeed2?src=pr&el=tree#diff-c3JjL2F6dXJlLWNsaS1jb3JlL2F6dXJlL2NsaS9jb3JlL19wcm9maWxlLnB5) | `84.19% <100%> (+0.13%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/Azure/azure-cli/pull/2575?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/Azure/azure-cli/pull/2575?src=pr&el=footer). Last update [3b6324d...3eb700a](https://codecov.io/gh/Azure/azure-cli/compare/3b6324d00353405e547723056bb324fe3667731c...3eb700a6096e68ea881880a9e976c43d060eeed2?el=footer&src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).
diff --git a/src/azure-cli-core/azure/cli/core/_profile.py b/src/azure-cli-core/azure/cli/core/_profile.py
index 2312aa240..6c68bddcb 100644
--- a/src/azure-cli-core/azure/cli/core/_profile.py
+++ b/src/azure-cli-core/azure/cli/core/_profile.py
@@ -182,16 +182,22 @@ class Profile(object):
                 s[_IS_DEFAULT_SUBSCRIPTION] = False
 
             if not new_active_one:
-                new_active_one = new_subscriptions[0]
-            new_active_one[_IS_DEFAULT_SUBSCRIPTION] = True
-            default_sub_id = new_active_one[_SUBSCRIPTION_ID]
+                new_active_one = Profile._pick_working_subscription(new_subscriptions)
         else:
-            new_subscriptions[0][_IS_DEFAULT_SUBSCRIPTION] = True
-            default_sub_id = new_subscriptions[0][_SUBSCRIPTION_ID]
+            new_active_one = Profile._pick_working_subscription(new_subscriptions)
+
+        new_active_one[_IS_DEFAULT_SUBSCRIPTION] = True
+        default_sub_id = new_active_one[_SUBSCRIPTION_ID]
 
         set_cloud_subscription(active_cloud.name, default_sub_id)
         self._storage[_SUBSCRIPTIONS] = subscriptions
 
+    @staticmethod
+    def _pick_working_subscription(subscriptions):
+        from azure.mgmt.resource.subscriptions.models import SubscriptionState
+        s = next((x for x in subscriptions if x['state'] == SubscriptionState.enabled.value), None)
+        return s or subscriptions[0]
+
     def set_active_subscription(self, subscription):  # take id or name
         subscriptions = self.load_cached_subscriptions(all_clouds=True)
         active_cloud = get_active_cloud()

Login: do not set default on disabled subscriptions
diff --git a/src/azure-cli-core/tests/test_profile.py b/src/azure-cli-core/tests/test_profile.py
index 08ab8288f..2ce6494ed 100644
--- a/src/azure-cli-core/tests/test_profile.py
+++ b/src/azure-cli-core/tests/test_profile.py
@@ -165,6 +165,19 @@ class Test_Profile(unittest.TestCase):  # pylint: disable=too-many-public-method
         self.assertFalse(storage_mock['subscriptions'][1]['isDefault'])
         self.assertTrue(storage_mock['subscriptions'][0]['isDefault'])
 
+    def test_default_active_subscription_to_non_disabled_one(self):
+        storage_mock = {'subscriptions': None}
+        profile = Profile(storage_mock)
+
+        subscriptions = profile._normalize_properties(
+            self.user2, [self.subscription2, self.subscription1], False)
+
+        profile._set_subscriptions(subscriptions)
+
+        # verify we skip the overdued subscription and default to the 2nd one in the list
+        self.assertEqual(storage_mock['subscriptions'][1]['name'], self.subscription1.display_name)
+        self.assertTrue(storage_mock['subscriptions'][1]['isDefault'])
+
     def test_get_subscription(self):
         storage_mock = {'subscriptions': None}
         profile = Profile(storage_mock)

python scripts/dev_setup.py
parse_log_pytest
requirements.txt
pytest
apt-get update apt-get install -y gcc
3.5
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
adal==0.4.3
applicationinsights==0.10.0
argcomplete==1.8.0
astroid==1.4.9
attrs==22.2.0
autopep8==1.2.4
azure-batch==2.0.0
-e git+https://github.com/Azure/azure-cli.git@3b6324d00353405e547723056bb324fe3667731c#egg=azure_cli&subdirectory=src/azure-cli
-e git+https://github.com/Azure/azure-cli.git@3b6324d00353405e547723056bb324fe3667731c#egg=azure_cli_acr&subdirectory=src/command_modules/azure-cli-acr
-e git+https://github.com/Azure/azure-cli.git@3b6324d00353405e547723056bb324fe3667731c#egg=azure_cli_acs&subdirectory=src/command_modules/azure-cli-acs
-e git+https://github.com/Azure/azure-cli.git@3b6324d00353405e547723056bb324fe3667731c#egg=azure_cli_appservice&subdirectory=src/command_modules/azure-cli-appservice
-e git+https://github.com/Azure/azure-cli.git@3b6324d00353405e547723056bb324fe3667731c#egg=azure_cli_batch&subdirectory=src/command_modules/azure-cli-batch
-e git+https://github.com/Azure/azure-cli.git@3b6324d00353405e547723056bb324fe3667731c#egg=azure_cli_cloud&subdirectory=src/command_modules/azure-cli-cloud
-e git+https://github.com/Azure/azure-cli.git@3b6324d00353405e547723056bb324fe3667731c#egg=azure_cli_component&subdirectory=src/command_modules/azure-cli-component
-e git+https://github.com/Azure/azure-cli.git@3b6324d00353405e547723056bb324fe3667731c#egg=azure_cli_configure&subdirectory=src/command_modules/azure-cli-configure
-e git+https://github.com/Azure/azure-cli.git@3b6324d00353405e547723056bb324fe3667731c#egg=azure_cli_container&subdirectory=src/command_modules/azure-cli-container
-e git+https://github.com/Azure/azure-cli.git@3b6324d00353405e547723056bb324fe3667731c#egg=azure_cli_core&subdirectory=src/azure-cli-core
-e git+https://github.com/Azure/azure-cli.git@3b6324d00353405e547723056bb324fe3667731c#egg=azure_cli_datalake&subdirectory=src/command_modules/azure-cli-datalake
-e git+https://github.com/Azure/azure-cli.git@3b6324d00353405e547723056bb324fe3667731c#egg=azure_cli_documentdb&subdirectory=src/command_modules/azure-cli-documentdb
-e git+https://github.com/Azure/azure-cli.git@3b6324d00353405e547723056bb324fe3667731c#egg=azure_cli_feedback&subdirectory=src/command_modules/azure-cli-feedback
-e git+https://github.com/Azure/azure-cli.git@3b6324d00353405e547723056bb324fe3667731c#egg=azure_cli_find&subdirectory=src/command_modules/azure-cli-find
-e git+https://github.com/Azure/azure-cli.git@3b6324d00353405e547723056bb324fe3667731c#egg=azure_cli_iot&subdirectory=src/command_modules/azure-cli-iot
-e git+https://github.com/Azure/azure-cli.git@3b6324d00353405e547723056bb324fe3667731c#egg=azure_cli_keyvault&subdirectory=src/command_modules/azure-cli-keyvault
-e git+https://github.com/Azure/azure-cli.git@3b6324d00353405e547723056bb324fe3667731c#egg=azure_cli_network&subdirectory=src/command_modules/azure-cli-network
-e git+https://github.com/Azure/azure-cli.git@3b6324d00353405e547723056bb324fe3667731c#egg=azure_cli_nspkg&subdirectory=src/azure-cli-nspkg
-e git+https://github.com/Azure/azure-cli.git@3b6324d00353405e547723056bb324fe3667731c#egg=azure_cli_profile&subdirectory=src/command_modules/azure-cli-profile
-e git+https://github.com/Azure/azure-cli.git@3b6324d00353405e547723056bb324fe3667731c#egg=azure_cli_redis&subdirectory=src/command_modules/azure-cli-redis
-e git+https://github.com/Azure/azure-cli.git@3b6324d00353405e547723056bb324fe3667731c#egg=azure_cli_resource&subdirectory=src/command_modules/azure-cli-resource
-e git+https://github.com/Azure/azure-cli.git@3b6324d00353405e547723056bb324fe3667731c#egg=azure_cli_role&subdirectory=src/command_modules/azure-cli-role
-e git+https://github.com/Azure/azure-cli.git@3b6324d00353405e547723056bb324fe3667731c#egg=azure_cli_sql&subdirectory=src/command_modules/azure-cli-sql
-e git+https://github.com/Azure/azure-cli.git@3b6324d00353405e547723056bb324fe3667731c#egg=azure_cli_storage&subdirectory=src/command_modules/azure-cli-storage
-e git+https://github.com/Azure/azure-cli.git@3b6324d00353405e547723056bb324fe3667731c#egg=azure_cli_taskhelp&subdirectory=src/command_modules/azure-cli-taskhelp
-e git+https://github.com/Azure/azure-cli.git@3b6324d00353405e547723056bb324fe3667731c#egg=azure_cli_testsdk&subdirectory=src/azure-cli-testsdk
-e git+https://github.com/Azure/azure-cli.git@3b6324d00353405e547723056bb324fe3667731c#egg=azure_cli_utility_automation&subdirectory=scripts
-e git+https://github.com/Azure/azure-cli.git@3b6324d00353405e547723056bb324fe3667731c#egg=azure_cli_vm&subdirectory=src/command_modules/azure-cli-vm
azure-common==1.1.4
azure-core==1.24.2
azure-datalake-store==0.0.5
azure-graphrbac==0.30.0rc6
azure-keyvault==0.1.0
azure-mgmt-authorization==0.30.0rc6
azure-mgmt-batch==3.0.0
azure-mgmt-compute==0.33.1rc1
azure-mgmt-containerregistry==0.2.0
azure-mgmt-datalake-analytics==0.1.3
azure-mgmt-datalake-nspkg==3.0.1
azure-mgmt-datalake-store==0.1.3
azure-mgmt-dns==1.0.0
azure-mgmt-documentdb==0.1.0
azure-mgmt-iothub==0.2.1
azure-mgmt-keyvault==0.30.0
azure-mgmt-network==0.30.0
azure-mgmt-nspkg==3.0.2
azure-mgmt-redis==1.0.0
azure-mgmt-resource==0.30.2
azure-mgmt-sql==0.3.2
azure-mgmt-storage==0.31.0
azure-mgmt-trafficmanager==0.30.0rc6
azure-mgmt-web==0.31.0
azure-nspkg==3.0.2
azure-storage==0.33.0
certifi==2021.5.30
cffi==1.15.1
colorama==0.3.7
coverage==4.2
cryptography==40.0.2
flake8==3.2.1
importlib-metadata==4.8.3
iniconfig==1.1.1
isodate==0.7.0
jeepney==0.7.1
jmespath==0.10.0
keyring==23.4.1
lazy-object-proxy==1.7.1
mccabe==0.5.3
mock==1.3.0
msrest==0.4.29
msrestazure==0.4.34
nose==1.3.7
oauthlib==3.2.2
packaging==21.3
paramiko==2.0.2
pbr==6.1.1
pep8==1.7.1
pluggy==1.0.0
py==1.11.0
pyasn1==0.5.1
pycodestyle==2.2.0
pycparser==2.21
pyflakes==1.3.0
Pygments==2.1.3
PyJWT==2.4.0
pylint==1.5.4
pyOpenSSL==16.2.0
pyparsing==3.1.4
pytest==7.0.1
python-dateutil==2.9.0.post0
PyYAML==3.11
requests==2.9.1
requests-oauthlib==2.0.0
scp==0.15.0
SecretStorage==3.3.3
six==1.10.0
sshtunnel==0.4.0
tabulate==0.7.5
tomli==1.2.3
typing-extensions==4.1.1
urllib3==1.16
vcrpy==1.10.3
Whoosh==2.7.4
wrapt==1.16.0
xmltodict==0.14.2
zipp==3.6.0

name: azure-cli
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - adal==0.4.3
      - applicationinsights==0.10.0
      - argcomplete==1.8.0
      - astroid==1.4.9
      - attrs==22.2.0
      - autopep8==1.2.4
      - azure-batch==2.0.0
      - azure-common==1.1.4
      - azure-core==1.24.2
      - azure-datalake-store==0.0.5
      - azure-graphrbac==0.30.0rc6
      - azure-keyvault==0.1.0
      - azure-mgmt-authorization==0.30.0rc6
      - azure-mgmt-batch==3.0.0
      - azure-mgmt-compute==0.33.1rc1
      - azure-mgmt-containerregistry==0.2.0
      - azure-mgmt-datalake-analytics==0.1.3
      - azure-mgmt-datalake-nspkg==3.0.1
      - azure-mgmt-datalake-store==0.1.3
      - azure-mgmt-dns==1.0.0
      - azure-mgmt-documentdb==0.1.0
      - azure-mgmt-iothub==0.2.1
      - azure-mgmt-keyvault==0.30.0
      - azure-mgmt-network==0.30.0
      - azure-mgmt-nspkg==3.0.2
      - azure-mgmt-redis==1.0.0
      - azure-mgmt-resource==0.30.2
      - azure-mgmt-sql==0.3.2
      - azure-mgmt-storage==0.31.0
      - azure-mgmt-trafficmanager==0.30.0rc6
      - azure-mgmt-web==0.31.0
      - azure-nspkg==3.0.2
      - azure-storage==0.33.0
      - cffi==1.15.1
      - colorama==0.3.7
      - coverage==4.2
      - cryptography==40.0.2
      - flake8==3.2.1
      - importlib-metadata==4.8.3
      - iniconfig==1.1.1
      - isodate==0.7.0
      - jeepney==0.7.1
      - jmespath==0.10.0
      - keyring==23.4.1
      - lazy-object-proxy==1.7.1
      - mccabe==0.5.3
      - mock==1.3.0
      - msrest==0.4.29
      - msrestazure==0.4.34
      - nose==1.3.7
      - oauthlib==3.2.2
      - packaging==21.3
      - paramiko==2.0.2
      - pbr==6.1.1
      - pep8==1.7.1
      - pip==9.0.1
      - pluggy==1.0.0
      - py==1.11.0
      - pyasn1==0.5.1
      - pycodestyle==2.2.0
      - pycparser==2.21
      - pyflakes==1.3.0
      - pygments==2.1.3
      - pyjwt==2.4.0
      - pylint==1.5.4
      - pyopenssl==16.2.0
      - pyparsing==3.1.4
      - pytest==7.0.1
      - python-dateutil==2.9.0.post0
      - pyyaml==3.11
      - requests==2.9.1
      - requests-oauthlib==2.0.0
      - scp==0.15.0
      - secretstorage==3.3.3
      - setuptools==30.4.0
      - six==1.10.0
      - sshtunnel==0.4.0
      - tabulate==0.7.5
      - tomli==1.2.3
      - typing-extensions==4.1.1
      - urllib3==1.16
      - vcrpy==1.10.3
      - whoosh==2.7.4
      - wrapt==1.16.0
      - xmltodict==0.14.2
      - zipp==3.6.0
prefix: /opt/conda/envs/azure-cli

src/azure-cli-core/tests/test_profile.py::Test_Profile::test_default_active_subscription_to_non_disabled_one
src/azure-cli-core/tests/test_profile.py::Test_Profile::test_find_subscriptions_from_service_principal_using_cert src/azure-cli-core/tests/test_profile.py::Test_Profile::test_service_principal_auth_client_cert
src/azure-cli-core/tests/test_profile.py::Test_Profile::test_create_token_cache src/azure-cli-core/tests/test_profile.py::Test_Profile::test_credscache_add_new_sp_creds src/azure-cli-core/tests/test_profile.py::Test_Profile::test_credscache_load_tokens_and_sp_creds_with_cert src/azure-cli-core/tests/test_profile.py::Test_Profile::test_credscache_load_tokens_and_sp_creds_with_secret src/azure-cli-core/tests/test_profile.py::Test_Profile::test_credscache_new_token_added_by_adal src/azure-cli-core/tests/test_profile.py::Test_Profile::test_credscache_remove_creds src/azure-cli-core/tests/test_profile.py::Test_Profile::test_find_subscriptions_from_particular_tenent src/azure-cli-core/tests/test_profile.py::Test_Profile::test_find_subscriptions_from_service_principal_id src/azure-cli-core/tests/test_profile.py::Test_Profile::test_find_subscriptions_interactive_from_particular_tenent src/azure-cli-core/tests/test_profile.py::Test_Profile::test_find_subscriptions_through_interactive_flow src/azure-cli-core/tests/test_profile.py::Test_Profile::test_find_subscriptions_thru_username_password src/azure-cli-core/tests/test_profile.py::Test_Profile::test_get_current_account_user src/azure-cli-core/tests/test_profile.py::Test_Profile::test_get_expanded_subscription_info src/azure-cli-core/tests/test_profile.py::Test_Profile::test_get_login_credentials src/azure-cli-core/tests/test_profile.py::Test_Profile::test_get_login_credentials_for_graph_client src/azure-cli-core/tests/test_profile.py::Test_Profile::test_get_subscription src/azure-cli-core/tests/test_profile.py::Test_Profile::test_load_cached_tokens src/azure-cli-core/tests/test_profile.py::Test_Profile::test_logout src/azure-cli-core/tests/test_profile.py::Test_Profile::test_logout_all src/azure-cli-core/tests/test_profile.py::Test_Profile::test_normalize src/azure-cli-core/tests/test_profile.py::Test_Profile::test_service_principal_auth_client_secret src/azure-cli-core/tests/test_profile.py::Test_Profile::test_set_active_subscription src/azure-cli-core/tests/test_profile.py::Test_Profile::test_update_add_two_different_subscriptions src/azure-cli-core/tests/test_profile.py::Test_Profile::test_update_with_same_subscription_added_twice
src/azure-cli-core/azure/cli/core/_profile.py
src/azure-cli-core/azure/cli/core/_profile.py