Skip to content

Commit

Permalink
Merge pull request #1870 from uProxy/freedom-typings
Browse files Browse the repository at this point in the history
Start using the new freedom typings from DefinitelyTyped
  • Loading branch information
jpevarnek committed Sep 8, 2015
2 parents ed67994 + ff4fa50 commit 9f5a625
Show file tree
Hide file tree
Showing 22 changed files with 80 additions and 75 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"lodash": "^3.7.0",
"regex2dfa": "^0.1.6",
"tsd": "^0.6.3",
"uproxy-lib": "^30.0.0",
"uproxy-lib": "^31.0.0",
"utransformers": "^0.2.1",
"xregexp": "^2.0.0"
},
Expand Down
10 changes: 4 additions & 6 deletions src/cca/app/scripts/main.core-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,20 @@
* loaded.
*/

/// <reference path='../../../../../third_party/freedom-typings/freedom-core-env.d.ts' />
/// <reference path='../../../../../third_party/typings/freedom/freedom-core-env.d.ts' />
/// <reference path='../../../../../third_party/typings/chrome/chrome-app.d.ts'/>

import freedom_types = require('freedom.types');

import CordovaBrowserApi = require('./cordova_browser_api');

import uproxy_core_api = require('../../../interfaces/uproxy_core_api');

export interface OnEmitModule extends freedom_types.OnAndEmit<any,any> {};
export interface OnEmitModule extends freedom.OnAndEmit<any,any> {};
export interface OnEmitModuleFactory extends
freedom_types.FreedomModuleFactoryManager<OnEmitModule> {};
freedom.FreedomModuleFactoryManager<OnEmitModule> {};

// Remember which handlers freedom has installed.
var haveAppChannel :Function;
export var uProxyAppChannel :Promise<freedom_types.OnAndEmit<any,any>> =
export var uProxyAppChannel :Promise<freedom.OnAndEmit<any,any>> =
new Promise((F, R) => {
haveAppChannel = F;
});
Expand Down
5 changes: 2 additions & 3 deletions src/chrome/app/scripts/chrome_ui_connector.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/// <reference path='../../../../../third_party/freedom-typings/freedom-common.d.ts' />
/// <reference path='../../../../../third_party/typings/freedom/freedom.d.ts' />
/// <reference path='../../../../../third_party/typings/chrome/chrome.d.ts'/>
/// <reference path='../../../../../third_party/typings/chrome/chrome-app.d.ts'/>

import browser_connector = require('../../../interfaces/browser_connector');
import freedom_types = require('freedom.types');
import uproxy_core_api = require('../../../interfaces/uproxy_core_api');
import uproxy_chrome = require('../../../interfaces/chrome');

Expand All @@ -18,7 +17,7 @@ class ChromeUIConnector {
private onCredentials_ :(credentials?:Object, error?:Object) => void;
private INSTALL_INCOMPLETE_PAGE_ :string = '../install-incomplete.html';

constructor(private uProxyAppChannel_ :freedom_types.OnAndEmit<any,any>) {
constructor(private uProxyAppChannel_ :freedom.OnAndEmit<any,any>) {
this.extPort_ = null;
chrome.runtime.onConnectExternal.addListener(this.onConnect_);
// Until the extension is connected, we assume uProxy installation is
Expand Down
9 changes: 4 additions & 5 deletions src/chrome/app/scripts/main.core-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,22 @@
* loaded.
*/

/// <reference path='../../../../../third_party/freedom-typings/freedom-core-env.d.ts' />
/// <reference path='../../../../../third_party/typings/freedom/freedom-core-env.d.ts' />
/// <reference path='../../../../../third_party/typings/chrome/chrome-app.d.ts'/>

import freedom_types = require('freedom.types');

import Chrome_oauth = require('./chrome_oauth');
import ChromeUIConnector = require('./chrome_ui_connector');

export interface OnEmitModule extends freedom_types.OnAndEmit<any,any> {};
export interface OnEmitModule extends freedom.OnAndEmit<any,any> {};
export interface OnEmitModuleFactory extends
freedom_types.FreedomModuleFactoryManager<OnEmitModule> {};
freedom.FreedomModuleFactoryManager<OnEmitModule> {};

// Remember which handlers freedom has installed.
var oauthOptions :{connector:ChromeUIConnector;} = {
connector: null
};
export var uProxyAppChannel :freedom_types.OnAndEmit<any,any>;
export var uProxyAppChannel :freedom.OnAndEmit<any,any>;
export var moduleName = 'uProxy App Top Level';

freedom('generic_core/freedom-module.json', {
Expand Down
25 changes: 14 additions & 11 deletions src/generic_core/firewall.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/// <reference path='../../../third_party/typings/freedom/freedom.d.ts' />
/// <reference path='../../../third_party/typings/jasmine/jasmine.d.ts' />

import freedomMocker = require('../../../third_party/uproxy-lib/freedom/mocks/mock-freedom-in-module-env');
Expand Down Expand Up @@ -52,12 +53,14 @@ describe('firewall.SocialUserProfile', () => {
// Failed for reserved word on a string field
{
'userId' : '__proto__',
'timestamp' : 7
'timestamp' : 7,
'name': 'John Doe',
},
// Failed numerical value on a number field.
{
'userId' : 'alice@gmail.com',
'timestamp' : -1
'timestamp' : -1,
'name': 'John Doe',
}]

var goodUserProfile = {
Expand All @@ -76,13 +79,13 @@ describe('firewall.SocialUserProfile', () => {

it('accepts good profiles', () => {
expect(firewall.isValidUserProfile(
<freedom_Social.UserProfile> goodUserProfile, policy)).toBe(true);
<freedom.Social.UserProfile> goodUserProfile, policy)).toBe(true);
});

it('rejects structurally-different profiles', () => {
for (var i in schemaFailingUserProfiles) {
expect(firewall.isValidUserProfile(
<freedom_Social.UserProfile> schemaFailingUserProfiles[i],
<freedom.Social.UserProfile> schemaFailingUserProfiles[i],
policy)).toBe(false);
}
expect(policy.failures).toBe(schemaFailingUserProfiles.length);
Expand All @@ -91,7 +94,7 @@ describe('firewall.SocialUserProfile', () => {
it('rejects profiles with bad values', () => {
for (var i in valueFailingUserProfiles) {
expect(firewall.isValidUserProfile(
<freedom_Social.UserProfile> valueFailingUserProfiles[i],
<freedom.Social.UserProfile> valueFailingUserProfiles[i],
policy)).toBe(false);
}
expect(policy.failures).toBe(valueFailingUserProfiles.length);
Expand Down Expand Up @@ -155,13 +158,13 @@ describe('firewall.SocialClientState', () => {

it('accepts good client states', () => {
expect(firewall.isValidClientState(
<freedom_Social.ClientState> goodClientState, policy)).toBe(true);
<freedom.Social.ClientState> goodClientState, policy)).toBe(true);
});

it('rejects structurally-different client states', () => {
for (var i in schemaFailingClientStates) {
expect(firewall.isValidClientState(
<freedom_Social.ClientState> schemaFailingClientStates[i],
<freedom.Social.ClientState> schemaFailingClientStates[i],
policy)).toBe(false);
}
expect(policy.failures).toBe(schemaFailingClientStates.length);
Expand All @@ -170,7 +173,7 @@ describe('firewall.SocialClientState', () => {
it('rejects client states with bad values', () => {
for (var i in valueFailingClientStates) {
expect(firewall.isValidClientState(
<freedom_Social.ClientState> valueFailingClientStates[i],
<freedom.Social.ClientState> valueFailingClientStates[i],
policy)).toBe(false);
}
expect(policy.failures).toBe(valueFailingClientStates.length);
Expand Down Expand Up @@ -249,13 +252,13 @@ describe('firewall.SocialIncomingMessage', () => {

it('accepts good incoming messages', () => {
expect(firewall.isValidIncomingMessage(
<freedom_Social.IncomingMessage> goodIncomingMessage, policy)).toBe(true);
<freedom.Social.IncomingMessage> goodIncomingMessage, policy)).toBe(true);
});

it('rejects structurally-different incoming messages', () => {
for (var i in schemaFailingIncomingMessages) {
expect(firewall.isValidIncomingMessage(
<freedom_Social.IncomingMessage> schemaFailingIncomingMessages[i],
<freedom.Social.IncomingMessage> schemaFailingIncomingMessages[i],
policy)).toBe(false);
}
expect(policy.failures).toBe(schemaFailingIncomingMessages.length);
Expand All @@ -264,7 +267,7 @@ describe('firewall.SocialIncomingMessage', () => {
it('rejects incoming messages with bad values', () => {
for (var i in valueFailingIncomingMessages) {
expect(firewall.isValidIncomingMessage(
<freedom_Social.IncomingMessage> valueFailingIncomingMessages[i],
<freedom.Social.IncomingMessage> valueFailingIncomingMessages[i],
policy)).toBe(false);
}
expect(policy.failures).toBe(valueFailingIncomingMessages.length);
Expand Down
8 changes: 4 additions & 4 deletions src/generic_core/firewall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* visual trickery. See http://www.unicode.org/reports/tr36/#visual_spoofing
*/

/// <reference path='../../../third_party/freedom-typings/social.d.ts' />
/// <reference path='../../../third_party/typings/freedom/freedom.d.ts' />

import logging = require('../../../third_party/uproxy-lib/logging/logging');

Expand Down Expand Up @@ -137,7 +137,7 @@ import logging = require('../../../third_party/uproxy-lib/logging/logging');
object_keys_matched == 0;
}

export function isValidUserProfile(profile :freedom_Social.UserProfile,
export function isValidUserProfile(profile :freedom.Social.UserProfile,
response :ResponsePolicy) : boolean {
if (response == null) {
response = DEFAULT_RESPONSE_POLICY;
Expand Down Expand Up @@ -179,7 +179,7 @@ import logging = require('../../../third_party/uproxy-lib/logging/logging');
'lastSeen' : '?number'
};

export function isValidClientState(state :freedom_Social.ClientState,
export function isValidClientState(state :freedom.Social.ClientState,
response :ResponsePolicy) : boolean {
if (response == null) {
response = DEFAULT_RESPONSE_POLICY;
Expand Down Expand Up @@ -223,7 +223,7 @@ import logging = require('../../../third_party/uproxy-lib/logging/logging');
'message' : 'string'
};

export function isValidIncomingMessage(state :freedom_Social.IncomingMessage,
export function isValidIncomingMessage(state :freedom.Social.IncomingMessage,
response :ResponsePolicy) :boolean {
if (response == null) {
response = DEFAULT_RESPONSE_POLICY;
Expand Down
3 changes: 1 addition & 2 deletions src/generic_core/freedom-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
* - Instances, which is a list of active uProxy installs.
*/

/// <reference path='../../../third_party/freedom-typings/freedom-module-env.d.ts' />
/// <reference path='../../../third_party/freedom-typings/social.d.ts' />
/// <reference path='../../../third_party/typings/freedom/freedom.d.ts' />

import logging = require('../../../third_party/uproxy-lib/logging/logging');
import uproxy_core_api = require('../interfaces/uproxy_core_api');
Expand Down
6 changes: 3 additions & 3 deletions src/generic_core/globals.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference path='../../../third_party/freedom-typings/pgp.d.ts' />
/// <reference path='../../../third_party/typings/freedom/freedom-module-env.d.ts' />

import local_storage = require('./storage');
import logging = require('../../../third_party/uproxy-lib/logging/logging');
Expand Down Expand Up @@ -81,10 +81,10 @@ export var effectiveMessageVersion = () : number => {
export var metrics = new metrics_module.Metrics(storage);

export var publicKey :string;
export var pgp :PgpProvider = freedom['pgp']();
export var pgp :freedom.PgpProvider.PgpProvider = freedom['pgp']();

pgp.setup('', '<uproxy>').then(() => {
pgp.exportKey().then((key :PublicKey) => {
pgp.exportKey().then((key :freedom.PgpProvider.PublicKey) => {
publicKey = key.key;
});
}).catch((e) => {
Expand Down
8 changes: 4 additions & 4 deletions src/generic_core/remote-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* It handles the signaling channel between two peers, regardless of permission.
*/

/// <reference path='../../../third_party/freedom-typings/port-control.d.ts' />
/// <reference path='../../../third_party/typings/freedom/freedom-module-env.d.ts' />

import globals = require('./globals');
import logging = require('../../../third_party/uproxy-lib/logging/logging');
Expand Down Expand Up @@ -73,7 +73,7 @@ var generateProxyingSessionId_ = (): string => {
constructor(
sendUpdate :(x :uproxy_core_api.Update, data?:Object) => void,
private userId_?:string,
private portControl_?:freedom_PortControl.PortControl
private portControl_?:freedom.PortControl.PortControl
) {
this.sendUpdate_ = sendUpdate;
this.resetSharerCreated();
Expand Down Expand Up @@ -131,7 +131,7 @@ var generateProxyingSessionId_ = (): string => {
throw new Error('rtcToNet_ already exists');
}

var config :freedom_RTCPeerConnection.RTCConfiguration = {
var config :freedom.RTCPeerConnection.RTCConfiguration = {
iceServers: globals.settings.stunServers
};

Expand Down Expand Up @@ -272,7 +272,7 @@ var generateProxyingSessionId_ = (): string => {
port: 0
});

var config :freedom_RTCPeerConnection.RTCConfiguration = {
var config :freedom.RTCPeerConnection.RTCConfiguration = {
iceServers: globals.settings.stunServers
};

Expand Down
4 changes: 2 additions & 2 deletions src/generic_core/remote-instance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ describe('remote_instance.RemoteInstance', () => {
var fakeSocksToRtc = {
handlers: <{[key :string] :Function}>{},
'start':
(endpoint:net.Endpoint, pcConfig: freedom_RTCPeerConnection.RTCConfiguration) => {
(endpoint:net.Endpoint, pcConfig: freedom.RTCPeerConnection.RTCConfiguration) => {
return Promise.resolve(endpoint);
},
'on': (t:string, f:Function) => { fakeSocksToRtc.handlers[t] = f; },
Expand Down Expand Up @@ -201,7 +201,7 @@ describe('remote_instance.RemoteInstance', () => {
// // Mock socksToRtc to not fulfill start promise
// spyOn(socks_to_rtc, 'SocksToRtc').and.returnValue({
// 'start':
// (endpoint:net.Endpoint, pcConfig:freedom_RTCPeerConnection.RTCConfiguration) => {
// (endpoint:net.Endpoint, pcConfig:freedom.RTCPeerConnection.RTCConfiguration) => {
// return new Promise((F, R) => {});
// },
// 'on': (t:string, f:Function) => {},
Expand Down
4 changes: 2 additions & 2 deletions src/generic_core/remote-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* consent, proxying status, and any other signalling information.
*/

/// <reference path='../../../third_party/typings/freedom/freedom.d.ts' />
/// <reference path='../../../third_party/typings/lodash/lodash.d.ts' />
/// <reference path='../../../third_party/freedom-typings/pgp.d.ts' />

import consent = require('./consent');
import globals = require('./globals');
Expand Down Expand Up @@ -202,7 +202,7 @@ import Persistent = require('../interfaces/persistent');
} else {
return pgp.dearmor(<string>msg.data).then((cipherData :ArrayBuffer) => {
return pgp.verifyDecrypt(cipherData, this.publicKey);
}).then((result :VerifyDecryptResult) => {
}).then((result :freedom.PgpProvider.VerifyDecryptResult) => {
var decryptedSignal =
JSON.parse(arraybuffers.arrayBufferToString(result.data));
return this.handleDecryptedSignal_(msg.type, msg.version, decryptedSignal);
Expand Down
7 changes: 4 additions & 3 deletions src/generic_core/remote-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* The tricky bit is that the Instance is associated not with the 'human' chat
* client, but with the 'uProxy' non-human client.
*/
/// <reference path='../../../third_party/freedom-typings/freedom-module-env.d.ts' />
/// <reference path='../../../third_party/typings/freedom/freedom.d.ts' />

import logging = require('../../../third_party/uproxy-lib/logging/logging');
import remote_instance = require('./remote-instance');
Expand Down Expand Up @@ -53,7 +53,7 @@ var log :logging.Log = new logging.Log('remote-user');
// Name of the user as provided by the social network.
public name :string;
public clientIdToStatusMap :{ [clientId :string] :social.ClientStatus };
public profile :freedom_Social.UserProfile;
public profile :freedom.Social.UserProfile;

public consent :consent.State;

Expand Down Expand Up @@ -89,6 +89,7 @@ var log :logging.Log = new logging.Log('remote-user');
this.name = 'pending';
this.profile = {
userId: this.userId,
name: '',
timestamp: Date.now()
}
this.clientIdToStatusMap = {};
Expand All @@ -112,7 +113,7 @@ var log :logging.Log = new logging.Log('remote-user');
* Update the information about this user.
* The userId must match.
*/
public update = (profile :freedom_Social.UserProfile) : void => {
public update = (profile :freedom.Social.UserProfile) : void => {
if (profile.userId != this.userId) {
throw Error('Updating User ' + this.userId +
' with unexpected userID: ' + profile.userId);
Expand Down
Loading

0 comments on commit 9f5a625

Please sign in to comment.