def _test_open_domain_connect_template_asynclink(config): params = { "IP": "132.148.25.185", "RANDOMTEXT": "shm:1531371203:Hejo async" } dc = DomainConnect() context = dc.open_domain_connect_template_asynclink( 'asyncpage.' + config['TEST_DOMAIN'], 'exampleservice.domainconnect.org', 'template2', params=params, redirect_uri= 'https://exampleservice.domainconnect.org/async_oauth_response', service_id_in_path=config['ASYNC_SERVICE_IN_PATH']) code = input("Please enter code: ") context.code = code ctx = dc.get_async_token(context, test_credentials[context.config.providerName]) assert (ctx.access_token is not None), 'Access token missing' assert (ctx.access_token_expires_in is not None), 'Access token expiration data missing' assert (ctx.iat is not None), 'Access token iat missing' dc.apply_domain_connect_template_async(context, params=params)
def _test_get_domain_connect_async_token_refresh(config): params = {"IP": "132.148.25.185"} dc = DomainConnect() context = dc.open_domain_connect_template_asynclink( 'asyncpage.' + config['TEST_DOMAIN'], 'domainconnect.org', 'dynamicdns', params=params, redirect_uri='https://dynamicdns.domainconnect.org/ddnscode', service_id_in_path=config['ASYNC_SERVICE_IN_PATH']) code = input("Please enter code: ") context.code = code ctx = dc.get_async_token(context, test_credentials[context.config.providerName]) initial_token = ctx.access_token assert (ctx.access_token_expires_in is not None), 'Access token expiration data missing' assert (ctx.iat is not None), 'Access token iat missing' assert (ctx.refresh_token is not None), 'Refresh token missing' ctx.access_token_expires_in = 1 ctx = dc.get_async_token(ctx, test_credentials[context.config.providerName]) assert (initial_token != ctx.access_token), "Token not refreshed when expired"
def _test_get_domain_connect_async_conflict(config): if config["ASYNC_SERVICE_IN_PATH"]: print( "Skipping test as service in path does not support multiple templates in consent: {}" .format(config)) return params = { "IP": "132.148.25.184", "RANDOMTEXT": "shm:1531371203:Hejo async" } params2 = { "IP": "132.148.25.185", "RANDOMTEXT": "shm:1531371203:Hejo async in conflict" } dc = DomainConnect() context = dc.open_domain_connect_template_asynclink( domain='asyncpage-conflict.' + config['TEST_DOMAIN'], provider_id='exampleservice.domainconnect.org', service_id=['template1', 'template2'], params=params, redirect_uri= 'https://exampleservice.domainconnect.org/async_oauth_response', service_id_in_path=config['ASYNC_SERVICE_IN_PATH']) code = input("Please enter code: ") context.code = code ctx = dc.get_async_token(context, test_credentials[context.config.providerName]) assert (ctx.access_token is not None), 'Access token missing' assert (ctx.access_token_expires_in is not None), 'Access token expiration data missing' dc.apply_domain_connect_template_async(context, service_id='template1', params=params, force=True) try: dc.apply_domain_connect_template_async(context, service_id='template2', params=params2) assert False, '2. No error on apply' except ConflictOnApplyException: pass dc.apply_domain_connect_template_async(context, service_id='template2', params=params2, force=True)
def _test_get_domain_connect_async_token_refresh(config): params = {"IP": "132.148.25.185"} dc = DomainConnect() # use of DynDNS to always have refresh_token onboarded context = dc.open_domain_connect_template_asynclink( 'asyncpage.' + config['TEST_DOMAIN'], 'domainconnect.org', 'dynamicdns', params=params, redirect_uri='https://dynamicdns.domainconnect.org/ddnscode', service_id_in_path=config['ASYNC_SERVICE_IN_PATH']) code = input("Please enter code: ") context.code = code # for DYNDNS there are static credentials credentials = DomainConnectAsyncCredentials( client_id='domainconnect.org', client_secret='inconceivable', api_url=context.config.urlAPI) ctx = dc.get_async_token(context, credentials) initial_token = ctx.access_token assert (ctx.access_token_expires_in is not None), 'Access token expiration data missing' assert (ctx.iat is not None), 'Access token iat missing' assert (ctx.refresh_token is not None), 'Refresh token missing' ctx.access_token_expires_in = 1 ctx = dc.get_async_token(ctx, credentials) assert (initial_token != ctx.access_token), "Token not refreshed when expired" # test handling on invalid refresh token ctx.access_token_expires_in = 1 ctx.refresh_token = 'invalid' try: ctx = dc.get_async_token(ctx, credentials) assert False, "Expected AsyncTokenException on invalid token refresh" except AsyncTokenException as e: # the second variant is for GoDaddy not compatible with OAuth specification assert e.message.startswith("Failed to get async token") \ or e.message.startswith( "Cannot get async token: Invalid JSON returned (400): Provided token doesn't match the registered one"), \ "Unexpected error message on invalid refresh token: {}".format(e.message)