Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xjbieke
axios
提交
9ede644b
A
axios
项目概览
xjbieke
/
axios
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
axios
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9ede644b
编写于
12月 14, 2015
作者:
M
Matt Zabriskie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Better tests for btoa
上级
77b8966b
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
82 addition
and
81 deletion
+82
-81
test/specs/__setupBasicAuthTest.js
test/specs/__setupBasicAuthTest.js
+43
-0
test/specs/basicAuth.spec.js
test/specs/basicAuth.spec.js
+2
-40
test/specs/basicAuthWithPolyfill.spec.js
test/specs/basicAuthWithPolyfill.spec.js
+10
-41
test/specs/helpers/btoa.spec.js
test/specs/helpers/btoa.spec.js
+27
-0
未找到文件。
test/specs/__setupBasicAuthTest.js
0 → 100644
浏览文件 @
9ede644b
var
axios
=
require
(
'
../../index
'
);
module
.
exports
=
function
setupBasicAuthTest
()
{
beforeEach
(
function
()
{
jasmine
.
Ajax
.
install
();
});
afterEach
(
function
()
{
jasmine
.
Ajax
.
uninstall
();
});
it
(
'
should accept HTTP Basic auth with username/password
'
,
function
(
done
)
{
axios
({
url
:
'
/foo
'
,
auth
:
{
username
:
'
Aladdin
'
,
password
:
'
open sesame
'
}
});
setTimeout
(
function
()
{
var
request
=
jasmine
.
Ajax
.
requests
.
mostRecent
();
expect
(
request
.
requestHeaders
[
'
Authorization
'
]).
toEqual
(
'
Basic: QWxhZGRpbjpvcGVuIHNlc2FtZQ==
'
);
done
();
},
0
);
});
it
(
'
should fail to encode HTTP Basic auth credentials with non-Latin1 characters
'
,
function
(
done
)
{
axios
({
url
:
'
/foo
'
,
auth
:
{
username
:
'
Aladßç£☃din
'
,
password
:
'
open sesame
'
}
}).
then
(
function
(
response
)
{
done
(
new
Error
(
'
Should not succeed to make a HTTP Basic auth request with non-latin1 chars in credentials.
'
));
}).
catch
(
function
(
error
)
{
expect
(
error
.
message
).
toEqual
(
'
INVALID_CHARACTER_ERR: DOM Exception 5
'
);
done
();
});
});
};
test/specs/basicAuth.spec.js
浏览文件 @
9ede644b
var
axios
=
require
(
'
../../index
'
);
var
setupBasicAuthTest
=
require
(
'
./__setupBasicAuthTest
'
);
describe
(
'
basicAuth without btoa polyfill
'
,
function
()
{
beforeEach
(
function
()
{
jasmine
.
Ajax
.
install
();
});
afterEach
(
function
()
{
jasmine
.
Ajax
.
uninstall
();
});
it
(
'
should accept HTTP Basic auth with username/password
'
,
function
(
done
)
{
axios
({
url
:
'
/foo
'
,
auth
:
{
username
:
'
Aladdin
'
,
password
:
'
open sesame
'
}
});
setTimeout
(
function
()
{
var
request
=
jasmine
.
Ajax
.
requests
.
mostRecent
();
expect
(
request
.
requestHeaders
[
'
Authorization
'
]).
toEqual
(
'
Basic: QWxhZGRpbjpvcGVuIHNlc2FtZQ==
'
);
done
();
},
0
);
});
it
(
'
should fail to encode HTTP Basic auth credentials with non-Latin1 characters
'
,
function
(
done
)
{
axios
({
url
:
'
/foo
'
,
auth
:
{
username
:
'
Aladßç£☃din
'
,
password
:
'
open sesame
'
}
}).
then
(
function
(
response
)
{
done
(
new
Error
(
'
Should not succeed to make a HTTP Basic auth request with non-latin1 chars in credentials.
'
))
}).
catch
(
function
(
error
)
{
expect
(
error
.
message
).
toEqual
(
'
INVALID_CHARACTER_ERR: DOM Exception 5
'
)
done
()
});
});
setupBasicAuthTest
();
});
test/specs/basicAuthWithPolyfill.spec.js
浏览文件 @
9ede644b
var
axios
=
require
(
'
../../index
'
);
var
setupBasicAuthTest
=
require
(
'
./__setupBasicAuthTest
'
);
var
window_btoa
;
describe
(
'
basicAuth with btoa polyfill
'
,
function
()
{
beforeAll
(
function
()
{
this
.
original
_btoa
=
window
.
btoa
;
window
_btoa
=
window
.
btoa
;
window
.
btoa
=
undefined
;
})
afterAll
(
function
()
{
window
.
btoa
=
this
.
original_btoa
;
})
beforeEach
(
function
()
{
jasmine
.
Ajax
.
install
();
});
afterEach
(
function
()
{
jasmine
.
Ajax
.
uninstall
();
afterAll
(
function
()
{
window
.
btoa
=
window_btoa
;
window_btoa
=
undefined
;
});
it
(
'
should accept HTTP Basic auth with username/password
'
,
function
(
done
)
{
axios
({
url
:
'
/foo
'
,
auth
:
{
username
:
'
Aladdin
'
,
password
:
'
open sesame
'
}
});
setTimeout
(
function
()
{
var
request
=
jasmine
.
Ajax
.
requests
.
mostRecent
();
expect
(
request
.
requestHeaders
[
'
Authorization
'
]).
toEqual
(
'
Basic: QWxhZGRpbjpvcGVuIHNlc2FtZQ==
'
);
done
();
},
0
);
it
(
'
should not have native window.btoa
'
,
function
()
{
expect
(
window
.
btoa
).
toEqual
(
undefined
);
});
it
(
'
should fail to encode HTTP Basic auth credentials with non-Latin1 characters
'
,
function
(
done
)
{
axios
({
url
:
'
/foo
'
,
auth
:
{
username
:
'
Aladßç£☃din
'
,
password
:
'
open sesame
'
}
}).
then
(
function
(
response
)
{
done
(
new
Error
(
'
Should not succeed to make a HTTP Basic auth request with non-latin1 chars in credentials.
'
))
}).
catch
(
function
(
error
)
{
expect
(
error
.
message
).
toEqual
(
'
\'
btoa
\'
failed: The string to be encoded contains characters outside of the Latin1 range.
'
)
done
()
});
});
setupBasicAuthTest
();
});
test/specs/helpers/btoa.spec.js
0 → 100644
浏览文件 @
9ede644b
var
__btoa
=
require
(
'
../../../lib/helpers/btoa
'
);
describe
(
'
btoa polyfill
'
,
function
()
{
it
(
'
should behave the same as native window.btoa
'
,
function
()
{
var
data
=
'
Hello, world
'
;
expect
(
__btoa
(
data
)).
toEqual
(
window
.
btoa
(
data
));
});
it
(
'
should throw an error if char is out of range 0xFF
'
,
function
()
{
var
err1
,
err2
;
var
data
=
'
I ♡ Unicode!
'
;
try
{
window
.
btoa
(
data
);
}
catch
(
e
)
{
err1
=
e
;
}
try
{
__btoa
(
data
);
}
catch
(
e
)
{
err2
=
e
;
}
expect
(
err1
.
message
).
toEqual
(
err2
.
message
);
});
});
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录