def test_rotate_anaconda_token_notoken(
    azure_mock,
    travis_mock,
    circle_mock,
    drone_mock,
    appveyor_mock,
    appveyor,
    drone,
    circle,
    travis,
    azure,
    monkeypatch,
):
    user = "******"
    project = "bar"

    with pytest.raises(RuntimeError) as e:
        rotate_anaconda_token(
            user,
            project,
            None,
            drone=drone,
            circle=circle,
            travis=travis,
            azure=azure,
            appveyor=appveyor,
        )

    assert "anaconda token" in str(e.value)

    drone_mock.assert_not_called()
    circle_mock.assert_not_called()
    travis_mock.assert_not_called()
    azure_mock.assert_not_called()
    appveyor_mock.assert_not_called()
Exemplo n.º 2
0
    def __call__(self, args):
        from conda_smithy.anaconda_token_rotation import rotate_anaconda_token

        owner = args.user or args.organization
        repo = os.path.basename(os.path.abspath(args.feedstock_directory))

        print(
            "Updating the anaconda/binstar token. Can take up to ~30 seconds."
        )

        # do all providers first
        rotate_anaconda_token(
            owner,
            repo,
            args.feedstock_directory,
            drone=args.drone,
            circle=args.circle,
            travis=args.travis,
            azure=args.azure,
            appveyor=args.appveyor,
            token_name=args.token_name,
        )

        print("Successfully updated the anaconda/binstar token!")
        if args.appveyor:
            print(
                "Appveyor tokens are stored in the repo so you must commit the "
                "local changes and push them before the new token will be used!"
            )
def test_rotate_anaconda_token(
    azure_mock,
    travis_mock,
    circle_mock,
    drone_mock,
    appveyor_mock,
    get_ac_token,
    appveyor,
    drone,
    circle,
    travis,
    azure,
):
    user = "******"
    project = "bar"

    anaconda_token = "abc123"
    get_ac_token.return_value = anaconda_token

    rotate_anaconda_token(
        user,
        project,
        "abc",
        drone=drone,
        circle=circle,
        travis=travis,
        azure=azure,
        appveyor=appveyor,
        token_name="MY_FANCY_TOKEN",
    )

    if drone:
        drone_mock.assert_called_once_with(user, project, anaconda_token,
                                           "MY_FANCY_TOKEN")
    else:
        drone_mock.assert_not_called()

    if circle:
        circle_mock.assert_called_once_with(user, project, anaconda_token,
                                            "MY_FANCY_TOKEN")
    else:
        circle_mock.assert_not_called()

    if travis:
        travis_mock.assert_called_once_with(user, project, "abc",
                                            anaconda_token, "MY_FANCY_TOKEN")
    else:
        travis_mock.assert_not_called()

    if azure:
        azure_mock.assert_called_once_with(user, project, anaconda_token,
                                           "MY_FANCY_TOKEN")
    else:
        azure_mock.assert_not_called()

    if appveyor:
        appveyor_mock.assert_called_once_with("abc", anaconda_token,
                                              "MY_FANCY_TOKEN")
    else:
        appveyor_mock.assert_not_called()
def test_rotate_anaconda_token_provider_error(
    azure_mock,
    travis_mock,
    circle_mock,
    drone_mock,
    appveyor_mock,
    get_ac_token,
    provider,
):
    user = "******"
    project = "bar"

    anaconda_token = "abc123"
    get_ac_token.return_value = anaconda_token

    user = "******"
    project = "bar-feedstock"

    if provider == "drone":
        drone_mock.side_effect = ValueError("blah")
    if provider == "circle":
        circle_mock.side_effect = ValueError("blah")
    if provider == "travis":
        travis_mock.side_effect = ValueError("blah")
    if provider == "azure":
        azure_mock.side_effect = ValueError("blah")
    if provider == "appveyor":
        appveyor_mock.side_effect = ValueError("blah")

    with pytest.raises(RuntimeError) as e:
        rotate_anaconda_token(user, project, None)

    assert "on %s" % provider in str(e.value)
def test_rotate_anaconda_token_provider_error(
    github_actions_mock,
    azure_mock,
    travis_mock,
    circle_mock,
    drone_mock,
    appveyor_mock,
    get_ac_token,
    get_gh_token,
    provider,
):
    user = "******"
    project = "bar"

    anaconda_token = "abc123"
    get_ac_token.return_value = anaconda_token
    get_gh_token.return_value = None

    user = "******"
    project = "bar-feedstock"

    if provider == "drone":
        drone_mock.side_effect = ValueError("blah")
    if provider == "circle":
        circle_mock.side_effect = ValueError("blah")
    if provider == "travis":
        travis_mock.side_effect = ValueError("blah")
    if provider == "azure":
        azure_mock.side_effect = ValueError("blah")
    if provider == "appveyor":
        appveyor_mock.side_effect = ValueError("blah")
    if provider == "github_actions":
        github_actions_mock.side_effect = ValueError("blah")

    with pytest.raises(RuntimeError) as e:
        rotate_anaconda_token(user,
                              project,
                              None,
                              drone_endpoints=[drone_default_endpoint])

    assert "on %s" % provider.replace("_", " ") in str(e.value)
Exemplo n.º 6
0
    def __call__(self, args):
        from conda_smithy.anaconda_token_rotation import rotate_anaconda_token

        owner = args.user or args.organization
        repo = os.path.basename(os.path.abspath(args.feedstock_directory))

        if args.feedstock_config is None:
            args.feedstock_config = default_feedstock_config_path(
                args.feedstock_directory)

        print(
            "Updating the anaconda/binstar token. Can take up to ~30 seconds.")
        from conda_smithy.ci_register import drone_default_endpoint

        drone_endpoints = args.drone_endpoints
        if drone_endpoints is None:
            drone_endpoints = [drone_default_endpoint]

        # do all providers first
        rotate_anaconda_token(
            owner,
            repo,
            args.feedstock_config,
            drone=args.drone,
            circle=args.circle,
            travis=args.travis,
            azure=args.azure,
            appveyor=args.appveyor,
            github_actions=args.github_actions,
            token_name=args.token_name,
            drone_endpoints=drone_endpoints,
        )

        print(f"Successfully updated the anaconda/binstar token for "
              f"{args.feedstock_directory}!")
        if args.appveyor:
            print(
                "Appveyor tokens are stored in the repo so you must commit the "
                "local changes and push them before the new token will be used!"
            )
def test_rotate_anaconda_token(
    azure_mock,
    travis_mock,
    circle_mock,
    drone_mock,
    appveyor_mock,
    get_ac_token,
    appveyor,
    drone,
    circle,
    travis,
    azure,
):
    user = "******"
    project = "bar"

    anaconda_token = "abc123"
    get_ac_token.return_value = anaconda_token

    feedstock_config_path = "abc/conda-forge.yml"

    rotate_anaconda_token(
        user,
        project,
        feedstock_config_path,
        drone=drone,
        circle=circle,
        travis=travis,
        azure=azure,
        appveyor=appveyor,
        token_name="MY_FANCY_TOKEN",
        drone_endpoints=[drone_default_endpoint],
    )

    if drone:
        drone_mock.assert_called_once_with(
            user,
            project,
            anaconda_token,
            "MY_FANCY_TOKEN",
            drone_default_endpoint,
        )
    else:
        drone_mock.assert_not_called()

    if circle:
        circle_mock.assert_called_once_with(user, project, anaconda_token,
                                            "MY_FANCY_TOKEN")
    else:
        circle_mock.assert_not_called()

    if travis:
        travis_mock.assert_called_once_with(
            user,
            project,
            feedstock_config_path,
            anaconda_token,
            "MY_FANCY_TOKEN",
        )
    else:
        travis_mock.assert_not_called()

    if azure:
        azure_mock.assert_called_once_with(user, project, anaconda_token,
                                           "MY_FANCY_TOKEN")
    else:
        azure_mock.assert_not_called()

    if appveyor:
        appveyor_mock.assert_called_once_with(feedstock_config_path,
                                              anaconda_token, "MY_FANCY_TOKEN")
    else:
        appveyor_mock.assert_not_called()